various fixes

This commit is contained in:
Loredana Crusoveanu
2022-06-01 16:19:28 +03:00
parent 9836afb4d8
commit e33521139a
5 changed files with 36 additions and 13 deletions

View File

@@ -8,6 +8,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import org.apache.commons.io.ByteOrderMark;
@@ -43,7 +44,7 @@ public class IllegalCharacterUnitTest {
String line;
String actual = "";
try (BufferedReader br = new BufferedReader(new InputStreamReader(Objects.requireNonNull(ioStream)))) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(Objects.requireNonNull(ioStream), StandardCharsets.UTF_8))) {
while ((line = br.readLine()) != null) {
actual += line.replace("\uFEFF", "");
}

View File

@@ -13,50 +13,68 @@ public class PropertyResourceUnitTest {
@Test
public void givenLocaleUsAsDefualt_whenGetBundleForLocalePlPl_thenItShouldContain3ButtonsAnd1Label() {
Locale.setDefault(Locale.US);
Locale locale = Locale.getDefault();
Locale.setDefault(Locale.US);
ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("pl", "PL"));
assertTrue(bundle.keySet()
.containsAll(Arrays.asList("backButton", "helloLabel", "cancelButton", "continueButton", "helloLabelNoEncoding")));
Locale.setDefault(locale);
}
@Test
public void givenLocaleUsAsDefualt_whenGetBundleForLocaleFrFr_thenItShouldContainKeys1To3AndKey4() {
Locale.setDefault(Locale.US);
Locale locale = Locale.getDefault();
Locale.setDefault(Locale.US);
ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("fr", "FR"));
assertTrue(bundle.keySet()
.containsAll(Arrays.asList("deleteButton", "helloLabel", "cancelButton", "continueButton")));
Locale.setDefault(locale);
}
@Test
public void givenLocaleChinaAsDefualt_whenGetBundleForLocaleFrFr_thenItShouldOnlyContainKeys1To3() {
Locale.setDefault(Locale.CHINA);
Locale locale = Locale.getDefault();
Locale.setDefault(Locale.CHINA);
ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("fr", "FR"));
assertTrue(bundle.keySet()
.containsAll(Arrays.asList("continueButton", "helloLabel", "cancelButton")));
Locale.setDefault(locale);
}
@Test
public void givenLocaleChinaAsDefualt_whenGetBundleForLocaleFrFrAndExampleControl_thenItShouldOnlyContainKey5() {
Locale.setDefault(Locale.CHINA);
Locale locale = Locale.getDefault();
Locale.setDefault(Locale.CHINA);
ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("fr", "FR"), new ExampleControl());
assertTrue(bundle.keySet()
.containsAll(Arrays.asList("backButton", "helloLabel")));
Locale.setDefault(locale);
}
@Test
public void givenValuesDifferentlyEncoded_whenGetBundleForLocalePlPl_thenItShouldContain3ButtonsAnd1Label() {
ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("pl", "PL"));
Locale locale = Locale.getDefault();
System.out.println(Locale.getDefault());
System.out.println("file.encoding=" + System.getProperty("file.encoding"));
ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("pl", "PL"));
assertEquals(bundle.getString("helloLabel"), "cześć");
assertEquals(bundle.getString("helloLabelNoEncoding"), "czeÅ\u009BÄ\u0087");
// this depends on the local system encoding
//assertEquals(bundle.getString("helloLabelNoEncoding"), "czeÅ\u009BÄ\u0087");
Locale.setDefault(locale);
}
}