1212import com .thecoderscorner .menu .editorui .generator .core .VariableNameGenerator ;
1313import com .thecoderscorner .menu .editorui .uimodel .UIAnalogMenuItem ;
1414import com .thecoderscorner .menu .editorui .util .TestUtils ;
15+ import com .thecoderscorner .menu .persist .LocaleMappingHandler ;
16+ import com .thecoderscorner .menu .persist .PropertiesLocaleEnabledHandler ;
17+ import com .thecoderscorner .menu .persist .SafeBundleLoader ;
1518import javafx .application .Platform ;
1619import javafx .stage .Stage ;
1720import org .junit .jupiter .api .AfterEach ;
2427import org .testfx .matcher .control .LabeledMatchers ;
2528import org .testfx .matcher .control .TextInputControlMatchers ;
2629
30+ import java .io .File ;
31+ import java .io .IOException ;
32+ import java .nio .file .Files ;
33+ import java .nio .file .Path ;
34+ import java .util .Comparator ;
35+
2736import static org .junit .jupiter .api .Assertions .assertEquals ;
2837import static org .mockito .ArgumentMatchers .any ;
2938import static org .mockito .Mockito .atLeastOnce ;
3241
3342@ ExtendWith (ApplicationExtension .class )
3443public class UIAnalogMenuItemTest extends UIMenuItemTestBase {
44+ private Path tempPath ;
3545
3646 @ Start
37- public void setup (Stage stage ) {
47+ public void setup (Stage stage ) throws IOException {
48+ tempPath = Files .createTempDirectory ("i18ntest" );
3849 init (stage );
3950 }
4051
4152 @ AfterEach
42- protected void closeWindow () {
53+ protected void closeWindow () throws IOException {
4354 Platform .runLater (() -> stage .close ());
55+ Files .walk (tempPath )
56+ .sorted (Comparator .reverseOrder ())
57+ .map (Path ::toFile )
58+ .forEach (File ::delete );
4459 }
4560
4661 @ Test
@@ -64,6 +79,9 @@ void testEnteringBadValuesIntoAnalogEditor(FxRobot robot) throws InterruptedExce
6479 tryToEnterBadValueIntoField (robot , "unitNameField" , "nameField" , "too long" ,
6580 "WARNING Unit name: default storage on device is 4 characters" );
6681
82+ tryToEnterBadValueIntoField (robot , "unitNameField" , "nameField" , "%unknown" ,
83+ "WARNING Unit name: no locale entry in bundle" );
84+
6785 tryToEnterBadValueIntoField (robot , "divisorField" , "nameField" , "100000" ,
6886 "ERROR Divisor: Value must be between 0 and 10000" );
6987
@@ -126,7 +144,11 @@ void testEnteringValidValuesIntoAnalogEditor(FxRobot robot) throws InterruptedEx
126144 writeIntoField (robot , "unitNameField" , "dB" );
127145 writeIntoField (robot , "divisorField" , "2" );
128146
129- verifyThat ("#minMaxLabel" , LabeledMatchers .hasText ("Min value: -90.0dB. Max value -40.0dB." ));
147+ writeIntoField (robot , "unitNameField" , "%menu.item.unit" );
148+
149+ verifyThat ("#minMaxLabel" , LabeledMatchers .hasText ("Min value: -90.0VA. Max value -40.0VA." ));
150+
151+ writeIntoField (robot , "unitNameField" , "dB" , 20 );
130152
131153 writeIntoField (robot , "maxValueField" , "255" );
132154 verifyThat ("#minMaxLabel" , LabeledMatchers .hasText ("Min value: -90.0dB. Max value 37.5dB." ));
@@ -179,4 +201,18 @@ void testValidValuesNearLimits(FxRobot robot) throws InterruptedException {
179201 assertEquals (99 , MenuItemHelper .getValueFor (item , menuTree , -1 ));
180202 }
181203
204+ @ Override
205+ protected LocaleMappingHandler getTestLocaleHandler () {
206+ try {
207+ var coreFile = tempPath .resolve ("temp.properties" );
208+ Files .writeString (coreFile , """
209+ menu.item.name=hello world
210+ menu.item.unit=VA
211+ """ );
212+ return new PropertiesLocaleEnabledHandler (new SafeBundleLoader (tempPath , "temp" ));
213+ } catch (IOException e ) {
214+ throw new RuntimeException (e );
215+ }
216+ }
217+
182218}
0 commit comments