Skip to content

Commit

Permalink
Issue #1. Unit test for Unit Locale now works
Browse files Browse the repository at this point in the history
This unit tests was commented out because it did not work. Now, it works
as intended, and retrieves the names and abbreviations for Durations.
Some more tests will be implemented, e.g., the ones using special
symbols.
  • Loading branch information
averbraeck committed Jan 21, 2023
1 parent 5a9310e commit bf62ec9
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/test/java/org/djunits/locale/VerifyLocalizations.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ static String fixUnicodeEscapes(final String in)
public void verifyLocalizations() throws IOException, ClassNotFoundException, NoSuchMethodException, SecurityException,
IllegalAccessException, IllegalArgumentException, InvocationTargetException, URISyntaxException
{
String pathToResources = new File(getClass().getResource("/resources").toURI().getPath()).getAbsolutePath();
String referenceFileName = "localeunit.properties";
String pathToResources = new File(getClass().getResource("/resources/locale").toURI().getPath()).getAbsolutePath();
String referenceFileName = "unit_en.properties";
// system.out.println(pathToResources + "/" + referenceFileName);
// Parse the localeunit.properties file and store all the keys
List<String> reference =
Expand Down Expand Up @@ -133,7 +133,7 @@ public void verifyLocalizations() throws IOException, ClassNotFoundException, No
for (Path path : paths)
{
// System.out.println(path);
if (path.getFileName().toString().startsWith("localeunit_")
if (path.getFileName().toString().startsWith("unit_")
&& path.getFileName().toString().endsWith(".properties"))
{
// system.out.println("Verifying locale file " + path.getFileName().toString());
Expand Down Expand Up @@ -186,14 +186,17 @@ public void verifyLocalizations() throws IOException, ClassNotFoundException, No
* localizations.
* @throws URISyntaxException on error
*/
// @Test
// TODO: this does not yet work. We really have to rethink the use of Locales in djunits...
@Test
public final void checkUnitSystemsLocale() throws URISyntaxException
{
DefaultLocale.setLocale(Locale.US);
assertEquals("hour", DurationUnit.HOUR.getName());
DefaultLocale.setLocale(Locale.forLanguageTag("nl-NL"));
assertEquals("uur", DurationUnit.HOUR.getName());
Locale.setDefault(Locale.US);
assertEquals("Duration", DurationUnit.MINUTE.getLocalizedName());
assertEquals("h", DurationUnit.HOUR.getLocalizedDisplayAbbreviation());
assertEquals("hour", DurationUnit.HOUR.getLocalizedTextualAbbreviation());
Locale.setDefault(new Locale("nl", "NL"));
assertEquals("Tijdsduur", DurationUnit.MINUTE.getLocalizedName());
assertEquals("u", DurationUnit.HOUR.getLocalizedDisplayAbbreviation());
assertEquals("uur", DurationUnit.HOUR.getLocalizedTextualAbbreviation());
}

}

0 comments on commit bf62ec9

Please sign in to comment.