Skip to content

Commit 8a8f1df

Browse files
authored
Prevent Negative IDs
1 parent 0b01379 commit 8a8f1df

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/test/java/io/codemc/bot/MockJDA.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static List<MessageEmbed> getLatestEmbeds(MessageChannel channel) {
107107
}
108108

109109
public static InteractionHook mockInteractionHook(Member user, MessageChannel channel, InteractionType type) {
110-
return mockInteractionHook(user, channel, type, -1);
110+
return mockInteractionHook(user, channel, type, RANDOM.nextLong(0, Long.MAX_VALUE));
111111
}
112112

113113
public static InteractionHook mockInteractionHook(Member user, MessageChannel channel, InteractionType type, long id) {
@@ -167,7 +167,6 @@ public static InteractionHook mockInteractionHook(Interaction interaction) {
167167

168168
public static Interaction mockInteraction(Member user, MessageChannel channel, InteractionType type, long id) {
169169
Interaction interaction = mock(Interaction.class);
170-
long id0 = id == -1 ? RANDOM.nextLong() : id;
171170

172171
when(interaction.getJDA()).thenReturn(JDA);
173172
when(interaction.getChannel()).thenReturn(channel);
@@ -177,7 +176,7 @@ public static Interaction mockInteraction(Member user, MessageChannel channel, I
177176
when(interaction.getUser()).thenAnswer(inv -> user.getUser());
178177
when(interaction.getGuild()).thenReturn(GUILD);
179178
when(interaction.getTypeRaw()).thenReturn(type.getKey());
180-
when(interaction.getIdLong()).thenReturn(id0);
179+
when(interaction.getIdLong()).thenReturn(id);
181180

182181
return interaction;
183182
}
@@ -242,7 +241,7 @@ public static TextChannel mockChannel(String configName) {
242241
}
243242

244243
public static Message mockMessage(String content, MessageChannel channel) {
245-
return mockMessage(content, channel, RANDOM.nextLong());
244+
return mockMessage(content, channel, RANDOM.nextLong(0, Long.MAX_VALUE));
246245
}
247246

248247
public static Message mockMessage(String content, MessageChannel channel, long id) {
@@ -274,7 +273,7 @@ public static Message mockMessage(String content, MessageChannel channel, long i
274273
}
275274

276275
public static Message mockMessage(String content, List<MessageEmbed> embeds, MessageChannel channel) {
277-
return mockMessage(content, embeds, channel, RANDOM.nextLong());
276+
return mockMessage(content, embeds, channel, RANDOM.nextLong(0, Long.MAX_VALUE));
278277
}
279278

280279
public static Message mockMessage(String content, List<MessageEmbed> embeds, MessageChannel channel, long id) {
@@ -338,7 +337,7 @@ private static Guild mockGuild() {
338337
public static Member mockMember(String username) {
339338
Member member = JDAObjects.getMember(username, "0000");
340339

341-
long id = RANDOM.nextLong();
340+
long id = RANDOM.nextLong(0, Long.MAX_VALUE);
342341
members.put(id, member);
343342

344343
when(member.getJDA()).thenReturn(JDA);
@@ -438,7 +437,7 @@ public static long assertSlashCommandEvent(SlashCommandEvent event, TestCommandL
438437

439438
public static SlashCommandEvent mockSlashCommandEvent(MessageChannel channel, BotCommand command, Map<String, Object> options) {
440439
SlashCommandEvent event = mock(SlashCommandEvent.class);
441-
long id = RANDOM.nextLong();
440+
long id = RANDOM.nextLong(0, Long.MAX_VALUE);
442441

443442
when(event.getName()).thenAnswer(invocation -> command.getName());
444443
when(event.getSubcommandName()).thenAnswer(invocation -> command.getName());
@@ -531,7 +530,7 @@ public static long assertButtonInteractionEvent(ListenerAdapter listener, Button
531530
public static ButtonInteractionEvent mockButtonInteractionEvent(Message message, Button button) {
532531
ButtonInteractionEvent event = mock(ButtonInteractionEvent.class);
533532
TextChannel channel = message.getChannel().asTextChannel();
534-
long id = RANDOM.nextLong();
533+
long id = RANDOM.nextLong(0, Long.MAX_VALUE);
535534

536535
when(event.getGuild()).thenReturn(GUILD);
537536
when(event.getMessageChannel()).thenReturn(channel);

0 commit comments

Comments
 (0)