mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-11-01 08:39:31 +01:00
Add expectation for amount of messages received in MinecraftToDiscordChatMessageTest
This commit is contained in:
parent
e0ec1aa31c
commit
3b02c662da
@ -35,7 +35,7 @@ public class MinecraftToDiscordChatMessageTest {
|
|||||||
EventBus bus = discordSRV.eventBus();
|
EventBus bus = discordSRV.eventBus();
|
||||||
|
|
||||||
String testMessage = UUID.randomUUID().toString();
|
String testMessage = UUID.randomUUID().toString();
|
||||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
CompletableFuture<Integer> future = new CompletableFuture<>();
|
||||||
Listener listener = new Listener(testMessage, future);
|
Listener listener = new Listener(testMessage, future);
|
||||||
|
|
||||||
bus.subscribe(listener);
|
bus.subscribe(listener);
|
||||||
@ -87,7 +87,13 @@ public class MinecraftToDiscordChatMessageTest {
|
|||||||
));
|
));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
future.get(40, TimeUnit.SECONDS);
|
Integer amount = future.get(40, TimeUnit.SECONDS);
|
||||||
|
if (amount == null) {
|
||||||
|
Assertions.fail("Null amount returned by listener");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assertions.assertEquals(2, amount, "Amount of messages received from listener");
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
Assertions.fail(e.getCause());
|
Assertions.fail(e.getCause());
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
@ -101,21 +107,23 @@ public class MinecraftToDiscordChatMessageTest {
|
|||||||
public static class Listener {
|
public static class Listener {
|
||||||
|
|
||||||
private final String lookFor;
|
private final String lookFor;
|
||||||
private final CompletableFuture<Void> success;
|
private final CompletableFuture<Integer> success;
|
||||||
|
|
||||||
public Listener(String lookFor, CompletableFuture<Void> success) {
|
public Listener(String lookFor, CompletableFuture<Integer> success) {
|
||||||
this.lookFor = lookFor;
|
this.lookFor = lookFor;
|
||||||
this.success = success;
|
this.success = success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onForwarded(GameChatMessageForwardedEvent event) {
|
public void onForwarded(GameChatMessageForwardedEvent event) {
|
||||||
|
int count = 0;
|
||||||
for (ReceivedDiscordMessage message : event.getDiscordMessage().getMessages()) {
|
for (ReceivedDiscordMessage message : event.getDiscordMessage().getMessages()) {
|
||||||
String content = message.getContent();
|
String content = message.getContent();
|
||||||
if (content != null && content.contains(lookFor)) {
|
if (content != null && content.contains(lookFor)) {
|
||||||
success.complete(null);
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
success.complete(count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user