Skip to content

Commit

Permalink
test: fix test failing due to incorrect i18n initializing
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Jun 1, 2024
1 parent 4920acd commit ca0b98c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 12 additions & 1 deletion Allay-Server/src/main/java/org/allaymc/server/Allay.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void main(String[] args) {
long startTime = System.currentTimeMillis();
System.setProperty("joml.format", "false"); // Set JOML vectors are output without a scientific notation
System.setProperty("log4j2.contextSelector", AsyncLoggerContextSelector.class.getName()); // Enable async logging
AllayAPI.getInstance().bindI18n(new AllayI18N(new AllayI18nLoader(), Server.SETTINGS.genericSettings().language()));
initI18n();
// Check if the environment is headless
if (isHeadless()) {
Server.SETTINGS.genericSettings().enableGui(false);
Expand Down Expand Up @@ -119,6 +119,10 @@ private static boolean isHeadless() {
return true;
}

/**
* NOTICE: The i18n implementation must be registered before initializing the API,
* which means that you should call initI18n() before call initAllayAPI()!
*/
@VisibleForTesting
public static void initAllayAPI() throws MissingImplementationException {
var api = AllayAPI.getInstance();
Expand Down Expand Up @@ -186,4 +190,11 @@ public static void initAllayAPI() throws MissingImplementationException {

api.implement("Allay");
}

@VisibleForTesting
public static void initI18n() {
if (I18n.get() == null) {
AllayAPI.getInstance().bindI18n(new AllayI18N(new AllayI18nLoader(), Server.SETTINGS.genericSettings().language()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class AllayTestExtension implements BeforeAllCallback {

@Override
public void beforeAll(ExtensionContext context) throws Exception {
if (!AllayAPI.getInstance().isImplemented()) Allay.initAllayAPI();
if (!AllayAPI.getInstance().isImplemented()) {
Allay.initI18n();
Allay.initAllayAPI();
}
}
}

0 comments on commit ca0b98c

Please sign in to comment.