Make MockDiscordSRV initialization failures log better

This commit is contained in:
Vankka 2024-12-20 23:04:36 +02:00
parent bb3c4987bc
commit f4368a15b8
No known key found for this signature in database
GPG Key ID: 62E48025ED4E7EBB
8 changed files with 36 additions and 15 deletions

View File

@ -46,8 +46,8 @@ public class FullBootExtension implements BeforeAllCallback, ExtensionContext.St
try {
System.out.println("Enabling...");
MockDiscordSRV.INSTANCE.enable();
MockDiscordSRV.INSTANCE.waitForStatus(DiscordSRVApi.Status.CONNECTED);
MockDiscordSRV.getInstance().enable();
MockDiscordSRV.getInstance().waitForStatus(DiscordSRVApi.Status.CONNECTED);
System.out.println("Enabled successfully");
} catch (Throwable e) {
Assertions.fail(e);
@ -57,7 +57,7 @@ public class FullBootExtension implements BeforeAllCallback, ExtensionContext.St
@Override
public void close() {
System.out.println("Disabling...");
MockDiscordSRV.INSTANCE.disable();
MockDiscordSRV.getInstance().disable();
System.out.println("Disabled successfully");
}
}

View File

@ -57,10 +57,30 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import static org.junit.jupiter.api.Assertions.fail;
@SuppressWarnings("ConstantConditions")
public class MockDiscordSRV extends AbstractDiscordSRV<IBootstrap, MainConfig, ConnectionConfig, MessagesConfig> {
public static final MockDiscordSRV INSTANCE = new MockDiscordSRV();
private static MockDiscordSRV INSTANCE = null;
private static Throwable FAILED_TO_GET_INSTANCE = null;
public static MockDiscordSRV getInstance() {
if (FAILED_TO_GET_INSTANCE != null) {
fail("Failed to make MockDiscordSRV instance", FAILED_TO_GET_INSTANCE);
assert false;
}
if (INSTANCE != null) {
return INSTANCE;
}
try {
return INSTANCE = new MockDiscordSRV();
} catch (Throwable t) {
FAILED_TO_GET_INSTANCE = t;
return getInstance();
}
}
public boolean configLoaded = false;
public boolean connectionConfigLoaded = false;

View File

@ -29,8 +29,9 @@ public class ConfigsLoadOnEnableTest {
@Test
public void configsLoaded() {
Assertions.assertTrue(MockDiscordSRV.INSTANCE.configLoaded, "Config loaded");
Assertions.assertTrue(MockDiscordSRV.INSTANCE.connectionConfigLoaded, "Connection config loaded");
Assertions.assertTrue(MockDiscordSRV.INSTANCE.messagesConfigLoaded, "Messages config loaded");
MockDiscordSRV discordSRV = MockDiscordSRV.getInstance();
Assertions.assertTrue(discordSRV.configLoaded, "Config loaded");
Assertions.assertTrue(discordSRV.connectionConfigLoaded, "Connection config loaded");
Assertions.assertTrue(discordSRV.messagesConfigLoaded, "Messages config loaded");
}
}

View File

@ -31,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class EventBusTest {
private static final Listener listener = new Listener();
private static final EventBus eventBus = MockDiscordSRV.INSTANCE.eventBus();
private static final EventBus eventBus = MockDiscordSRV.getInstance().eventBus();
@BeforeAll
public static void subscribe() {

View File

@ -41,7 +41,7 @@ import static org.junit.jupiter.api.Assertions.*;
public class RequirementTypeParserTest {
private final RequirementParser requirementParser = RequirementParser.getInstance();
private final RequiredLinkingModule<?> module = new RequiredLinkingModule<DiscordSRV>(MockDiscordSRV.INSTANCE) {
private final RequiredLinkingModule<?> module = new RequiredLinkingModule<DiscordSRV>(MockDiscordSRV.getInstance()) {
@Override
public RequiredLinkingConfig config() {
return null;

View File

@ -57,7 +57,7 @@ public class MinecraftToDiscordChatMessageTest {
@Test
public void runTest() throws InterruptedException {
DiscordSRV discordSRV = MockDiscordSRV.INSTANCE;
DiscordSRV discordSRV = MockDiscordSRV.getInstance();
EventBus bus = discordSRV.eventBus();
String testMessage = UUID.randomUUID().toString();
@ -69,7 +69,7 @@ public class MinecraftToDiscordChatMessageTest {
try {
TestHelper.set(future::completeExceptionally);
MockDiscordSRV.INSTANCE.eventBus().publish(
discordSRV.eventBus().publish(
new GameChatMessageReceiveEvent(
null,
new IPlayer() {
@ -86,7 +86,7 @@ public class MinecraftToDiscordChatMessageTest {
@Override
public DiscordSRV discordSRV() {
return MockDiscordSRV.INSTANCE;
return discordSRV;
}
@Override
@ -129,7 +129,7 @@ public class MinecraftToDiscordChatMessageTest {
public void runCommand(String command) {}
},
ComponentUtil.toAPI(Component.text(testMessage)),
new GlobalChannel(MockDiscordSRV.INSTANCE),
new GlobalChannel(discordSRV),
false
));

View File

@ -28,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
public class PlaceholderServiceTest {
private final PlaceholderService service = MockDiscordSRV.INSTANCE.placeholderService();
private final PlaceholderService service = MockDiscordSRV.getInstance().placeholderService();
@Test
public void staticFieldTest() {

View File

@ -29,6 +29,6 @@ public class PlayerProviderBootTest {
@Test
public void subscribed() {
Assertions.assertTrue(MockDiscordSRV.INSTANCE.playerProviderSubscribed, "Player provider subscribed");
Assertions.assertTrue(MockDiscordSRV.getInstance().playerProviderSubscribed, "Player provider subscribed");
}
}