Skip to content

Commit

Permalink
Fixed localization tests
Browse files Browse the repository at this point in the history
Co-authored-by: Siedlerchr <siedlerkiller@gmail.com>
  • Loading branch information
calixtus and Siedlerchr committed Jan 30, 2021
1 parent bdb1560 commit cc29b5f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/test/java/org/jabref/logic/l10n/LocalizationParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -188,6 +191,9 @@ private static List<LocalizationEntry> getLocalizationParametersInJavaFile(Path
private static List<LocalizationEntry> getLanguageKeysInFxmlFile(Path path, LocalizationBundleForTest type) {
List<String> result = new ArrayList<>();

// Afterburner ViewLoader forces a controller factory, but we do not need any controller
MockedStatic<ViewLoader> 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() {

Expand All @@ -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()
Expand Down

0 comments on commit cc29b5f

Please sign in to comment.