From 9be5281672461b4aeeec4c313787b5b2498c1016 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Sat, 21 Oct 2017 11:53:09 +0200 Subject: [PATCH] Revised bundle name detection in AbstractFxmlView.getBundleName() Previously getBundleName() always returned the value from FXMLView#bundle attribute, due to testing the annotation instead of the bundle-name for being empty. We now correctly test the configured bundle-name. If the bundle name is null we or empty we derive the bundle name from the classname. Otherwise we use the value as is. Fixes #38 Can be backported to 1.4.x --- .../de/felixroske/jfxsupport/AbstractFxmlView.java | 10 +++++----- ...lName.java => AnnotatedUnconventionalNameTest.java} | 9 +++++---- src/test/resources/jfxtest/annotated/annotated.fxml | 2 +- .../resources/jfxtest/annotated/annotated.properties | 1 + 4 files changed, 12 insertions(+), 10 deletions(-) rename src/test/java/jfxtest/annotated/{AnnotatedUnconventionalName.java => AnnotatedUnconventionalNameTest.java} (80%) create mode 100644 src/test/resources/jfxtest/annotated/annotated.properties diff --git a/src/main/java/de/felixroske/jfxsupport/AbstractFxmlView.java b/src/main/java/de/felixroske/jfxsupport/AbstractFxmlView.java index ecade7c..de4fd16 100644 --- a/src/main/java/de/felixroske/jfxsupport/AbstractFxmlView.java +++ b/src/main/java/de/felixroske/jfxsupport/AbstractFxmlView.java @@ -354,15 +354,15 @@ private String getConventionalName() { * @return the bundle name */ private String getBundleName() { - if (!StringUtils.isEmpty(annotation)) { - final String lbundle = annotation.bundle(); - LOGGER.debug("Annotated bundle: {}", lbundle); - return lbundle; - } else { + if (StringUtils.isEmpty(annotation.bundle())) { final String lbundle = getClass().getPackage().getName() + "." + getConventionalName(); LOGGER.debug("Bundle: {} based on conventional name.", lbundle); return lbundle; } + + final String lbundle = annotation.bundle(); + LOGGER.debug("Annotated bundle: {}", lbundle); + return lbundle; } /** diff --git a/src/test/java/jfxtest/annotated/AnnotatedUnconventionalName.java b/src/test/java/jfxtest/annotated/AnnotatedUnconventionalNameTest.java similarity index 80% rename from src/test/java/jfxtest/annotated/AnnotatedUnconventionalName.java rename to src/test/java/jfxtest/annotated/AnnotatedUnconventionalNameTest.java index f0faed2..b38a8ab 100644 --- a/src/test/java/jfxtest/annotated/AnnotatedUnconventionalName.java +++ b/src/test/java/jfxtest/annotated/AnnotatedUnconventionalNameTest.java @@ -15,7 +15,7 @@ import javafx.scene.control.Button; @RunWith(SpringRunner.class) @SpringBootTest -public class AnnotatedUnconventionalName extends GuiTest { +public class AnnotatedUnconventionalNameTest extends GuiTest { @Autowired private Annotated buttonsView; @@ -25,12 +25,13 @@ public void constructView() throws Exception { init(buttonsView); } - @Test - /* + /* * Asserts that we can find a view if the class name doesn't end with 'view' + * see https://github.com/roskenet/springboot-javafx-support/issues/38 */ + @Test public void showsI18nText() throws Exception { Button theButton = (Button) find("#theButton"); - assertThat(theButton.getText(), is("The Button Text")); + assertThat(theButton.getText(), is("The default Button Text")); } } diff --git a/src/test/resources/jfxtest/annotated/annotated.fxml b/src/test/resources/jfxtest/annotated/annotated.fxml index d99a68c..4d83f27 100644 --- a/src/test/resources/jfxtest/annotated/annotated.fxml +++ b/src/test/resources/jfxtest/annotated/annotated.fxml @@ -5,6 +5,6 @@ -