From f12d3cd8ba47fb0d25f7c13e1f3a89d770bd34a6 Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 5 Aug 2023 10:49:57 +0100 Subject: [PATCH] Fix race error in bulk update integration test --- .../standalone/CommandsIntegrationTest.java | 2 +- .../standalone/utils/CommandTester.java | 43 ++++++++++++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/standalone/src/test/java/me/lucko/luckperms/standalone/CommandsIntegrationTest.java b/standalone/src/test/java/me/lucko/luckperms/standalone/CommandsIntegrationTest.java index 419960465..485a3ccbe 100644 --- a/standalone/src/test/java/me/lucko/luckperms/standalone/CommandsIntegrationTest.java +++ b/standalone/src/test/java/me/lucko/luckperms/standalone/CommandsIntegrationTest.java @@ -1086,7 +1086,7 @@ public class CommandsIntegrationTest { .givenHasPermissions("luckperms.bulkupdate") .whenRunCommand("bulkupdate all update permission group.mod \"permission == group.moderator\"") - .thenExpect("[LP] Running bulk update."); + .thenExpectStartsWith("[LP] Running bulk update."); assertTrue(completed.await(15, TimeUnit.SECONDS), "operation did not complete in the allotted time"); diff --git a/standalone/src/test/java/me/lucko/luckperms/standalone/utils/CommandTester.java b/standalone/src/test/java/me/lucko/luckperms/standalone/utils/CommandTester.java index bd6e16e93..97d85a0fc 100644 --- a/standalone/src/test/java/me/lucko/luckperms/standalone/utils/CommandTester.java +++ b/standalone/src/test/java/me/lucko/luckperms/standalone/utils/CommandTester.java @@ -45,8 +45,10 @@ import java.util.Set; import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Utility for testing LuckPerms commands with BDD-like given/when/then assertions. @@ -155,10 +157,7 @@ public final class CommandTester implements Consumer, Function, Function, Function renderBuffer() { - return this.messageBuffer.stream() - .map(component -> PlainTextComponentSerializer.plainText().serialize(component)) - .collect(Collectors.toList()); + public Stream renderBufferStream() { + return this.messageBuffer.stream().map(component -> PlainTextComponentSerializer.plainText().serialize(component)); + } + + /** + * Renders the contents of the message buffer as a joined string. + * + * @return rendered copy of the buffer + */ + public String renderBuffer() { + return this.renderBufferStream().map(String::trim).collect(Collectors.joining("\n")); } /** @@ -206,7 +229,7 @@ public final class CommandTester implements Consumer, Function render = this.renderBuffer(); + List render = this.renderBufferStream().toList(); if (render.size() == 1) { System.out.printf(".thenExpect(\"%s\")%n", render.get(0)); } else {