Merge pull request #12291 from eugenp/fix-test-failures

various fixes
This commit is contained in:
Loredana Crusoveanu 2022-06-01 16:23:00 +03:00 committed by GitHub
commit 1f96a77fec
5 changed files with 36 additions and 13 deletions

View File

@ -79,9 +79,7 @@ public class FileLocks {
while (buffer.hasRemaining()) { while (buffer.hasRemaining()) {
channel.write(buffer, channel.size()); channel.write(buffer, channel.size());
} }
LOG.debug("This was written to the file");
Files.lines(path)
.forEach(LOG::debug);
return lock; return lock;
} }
} }

View File

@ -4,6 +4,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.KeyStoreException; import java.security.KeyStoreException;
@ -48,7 +49,9 @@ public class JavaKeyStore {
void loadKeyStore() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { void loadKeyStore() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
char[] pwdArray = keyStorePassword.toCharArray(); char[] pwdArray = keyStorePassword.toCharArray();
keyStore.load(new FileInputStream(keyStoreName), pwdArray); FileInputStream fis = new FileInputStream(keyStoreName);
keyStore.load(fis, pwdArray);
fis.close();
} }
void setEntry(String alias, KeyStore.SecretKeyEntry secretKeyEntry, KeyStore.ProtectionParameter protectionParameter) throws KeyStoreException { void setEntry(String alias, KeyStore.SecretKeyEntry secretKeyEntry, KeyStore.ProtectionParameter protectionParameter) throws KeyStoreException {
@ -83,7 +86,9 @@ public class JavaKeyStore {
keyStore.deleteEntry(alias); keyStore.deleteEntry(alias);
} }
keyStore = null; keyStore = null;
Files.delete(Paths.get(keyStoreName));
Path keyStoreFile = Paths.get(keyStoreName);
Files.delete(keyStoreFile);
} }
KeyStore getKeyStore() { KeyStore getKeyStore() {

View File

@ -78,7 +78,8 @@ public class CharacterEncodingExamplesUnitTest {
Assertions.assertEquals("The faade pattern is a software design pattern.", CharacterEncodingExamples.decodeText("The façade pattern is a software design pattern.", StandardCharsets.US_ASCII, CodingErrorAction.IGNORE)); Assertions.assertEquals("The faade pattern is a software design pattern.", CharacterEncodingExamples.decodeText("The façade pattern is a software design pattern.", StandardCharsets.US_ASCII, CodingErrorAction.IGNORE));
} }
@Test //@Test
// run this manually as it's dependent on platform encoding, which has to be UTF-8
public void givenUTF8String_whenDecodeByUS_ASCII_thenReplaceMalformedInputSequence() throws IOException { public void givenUTF8String_whenDecodeByUS_ASCII_thenReplaceMalformedInputSequence() throws IOException {
Assertions.assertEquals( Assertions.assertEquals(
"The fa<66><61>ade pattern is a software design pattern.", "The fa<66><61>ade pattern is a software design pattern.",

View File

@ -8,6 +8,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.io.ByteOrderMark; import org.apache.commons.io.ByteOrderMark;
@ -43,7 +44,7 @@ public class IllegalCharacterUnitTest {
String line; String line;
String actual = ""; 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) { while ((line = br.readLine()) != null) {
actual += line.replace("\uFEFF", ""); actual += line.replace("\uFEFF", "");
} }

View File

@ -13,50 +13,68 @@ public class PropertyResourceUnitTest {
@Test @Test
public void givenLocaleUsAsDefualt_whenGetBundleForLocalePlPl_thenItShouldContain3ButtonsAnd1Label() { public void givenLocaleUsAsDefualt_whenGetBundleForLocalePlPl_thenItShouldContain3ButtonsAnd1Label() {
Locale locale = Locale.getDefault();
Locale.setDefault(Locale.US); Locale.setDefault(Locale.US);
ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("pl", "PL")); ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("pl", "PL"));
assertTrue(bundle.keySet() assertTrue(bundle.keySet()
.containsAll(Arrays.asList("backButton", "helloLabel", "cancelButton", "continueButton", "helloLabelNoEncoding"))); .containsAll(Arrays.asList("backButton", "helloLabel", "cancelButton", "continueButton", "helloLabelNoEncoding")));
Locale.setDefault(locale);
} }
@Test @Test
public void givenLocaleUsAsDefualt_whenGetBundleForLocaleFrFr_thenItShouldContainKeys1To3AndKey4() { public void givenLocaleUsAsDefualt_whenGetBundleForLocaleFrFr_thenItShouldContainKeys1To3AndKey4() {
Locale locale = Locale.getDefault();
Locale.setDefault(Locale.US); Locale.setDefault(Locale.US);
ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("fr", "FR")); ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("fr", "FR"));
assertTrue(bundle.keySet() assertTrue(bundle.keySet()
.containsAll(Arrays.asList("deleteButton", "helloLabel", "cancelButton", "continueButton"))); .containsAll(Arrays.asList("deleteButton", "helloLabel", "cancelButton", "continueButton")));
Locale.setDefault(locale);
} }
@Test @Test
public void givenLocaleChinaAsDefualt_whenGetBundleForLocaleFrFr_thenItShouldOnlyContainKeys1To3() { public void givenLocaleChinaAsDefualt_whenGetBundleForLocaleFrFr_thenItShouldOnlyContainKeys1To3() {
Locale locale = Locale.getDefault();
Locale.setDefault(Locale.CHINA); Locale.setDefault(Locale.CHINA);
ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("fr", "FR")); ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("fr", "FR"));
assertTrue(bundle.keySet() assertTrue(bundle.keySet()
.containsAll(Arrays.asList("continueButton", "helloLabel", "cancelButton"))); .containsAll(Arrays.asList("continueButton", "helloLabel", "cancelButton")));
Locale.setDefault(locale);
} }
@Test @Test
public void givenLocaleChinaAsDefualt_whenGetBundleForLocaleFrFrAndExampleControl_thenItShouldOnlyContainKey5() { public void givenLocaleChinaAsDefualt_whenGetBundleForLocaleFrFrAndExampleControl_thenItShouldOnlyContainKey5() {
Locale locale = Locale.getDefault();
Locale.setDefault(Locale.CHINA); Locale.setDefault(Locale.CHINA);
ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("fr", "FR"), new ExampleControl()); ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("fr", "FR"), new ExampleControl());
assertTrue(bundle.keySet() assertTrue(bundle.keySet()
.containsAll(Arrays.asList("backButton", "helloLabel"))); .containsAll(Arrays.asList("backButton", "helloLabel")));
Locale.setDefault(locale);
} }
@Test @Test
public void givenValuesDifferentlyEncoded_whenGetBundleForLocalePlPl_thenItShouldContain3ButtonsAnd1Label() { public void givenValuesDifferentlyEncoded_whenGetBundleForLocalePlPl_thenItShouldContain3ButtonsAnd1Label() {
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")); ResourceBundle bundle = ResourceBundle.getBundle("resourcebundle.resource", new Locale("pl", "PL"));
assertEquals(bundle.getString("helloLabel"), "cześć"); 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);
} }
} }