From cc29b5f234ab090e5e5a4faf6cd1fd42fb746052 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage Date: Sat, 30 Jan 2021 20:15:27 +0100 Subject: [PATCH] Fixed localization tests Co-authored-by: Siedlerchr --- .../java/org/jabref/logic/l10n/LocalizationParser.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/org/jabref/logic/l10n/LocalizationParser.java b/src/test/java/org/jabref/logic/l10n/LocalizationParser.java index e4b246e9bfb..b40e43b03a3 100644 --- a/src/test/java/org/jabref/logic/l10n/LocalizationParser.java +++ b/src/test/java/org/jabref/logic/l10n/LocalizationParser.java @@ -25,6 +25,9 @@ import javafx.fxml.FXMLLoader; +import com.airhacks.afterburner.views.ViewLoader; +import org.mockito.Answers; +import org.mockito.MockedStatic; import org.mockito.Mockito; public class LocalizationParser { @@ -188,6 +191,9 @@ private static List getLocalizationParametersInJavaFile(Path private static List getLanguageKeysInFxmlFile(Path path, LocalizationBundleForTest type) { List result = new ArrayList<>(); + // Afterburner ViewLoader forces a controller factory, but we do not need any controller + MockedStatic viewLoader = Mockito.mockStatic(ViewLoader.class, Answers.RETURNS_DEEP_STUBS); + // Record which keys are requested; we pretend that we have all keys ResourceBundle registerUsageResourceBundle = new ResourceBundle() { @@ -212,11 +218,14 @@ public boolean containsKey(String key) { FXMLLoader loader = new FXMLLoader(path.toUri().toURL(), registerUsageResourceBundle); // We don't want to initialize controller loader.setControllerFactory(Mockito::mock); + // We need to load in "static mode" because otherwise fxml files with fx:root doesn't work setStaticLoad(loader); loader.load(); } catch (IOException exception) { throw new RuntimeException(exception); + } finally { + viewLoader.close(); } return result.stream()