Skip to content

Commit b5907e0

Browse files
authored
Merge pull request eugenp#5676 from rozagerardo/geroza/BAEL-10301_fix-unit-tests-in-core-java-module
[BAEL-10301] core-java | fix unit tests
2 parents 400d28d + 55ba795 commit b5907e0

4 files changed

Lines changed: 26 additions & 9 deletions

File tree

core-java/src/test/java/com/baeldung/abstractclasses/LowercaseFileReaderUnitTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
22

33
import com.baeldung.abstractclasses.filereaders.BaseFileReader;
44
import com.baeldung.abstractclasses.filereaders.LowercaseFileReader;
5+
6+
import java.net.URL;
7+
import java.nio.file.Paths;
58
import java.util.List;
69
import static org.assertj.core.api.Assertions.assertThat;
710
import org.junit.Test;
811

912
public class LowercaseFileReaderUnitTest {
10-
13+
1114
@Test
1215
public void givenLowercaseFileReaderInstance_whenCalledreadFile_thenCorrect() throws Exception {
13-
String filePath = getClass().getClassLoader().getResource("files/test.txt").getPath().substring(1);
16+
// We'll transform the resource URL path to URI to load the file correctly in Windows
17+
URL url = getClass().getClassLoader().getResource("files/test.txt");
18+
String filePath = Paths.get(url.toURI()).toString();
1419
BaseFileReader lowercaseFileReader = new LowercaseFileReader(filePath);
15-
20+
1621
assertThat(lowercaseFileReader.readFile()).isInstanceOf(List.class);
1722
}
1823
}

core-java/src/test/java/com/baeldung/abstractclasses/StandardFileReaderUnitTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
package com.baeldung.abstractclasses;
22

3-
import com.baeldung.abstractclasses.filereaders.BaseFileReader;
4-
import com.baeldung.abstractclasses.filereaders.StandardFileReader;
5-
import java.util.List;
63
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.net.URL;
6+
import java.nio.file.Paths;
7+
import java.util.List;
8+
79
import org.junit.Test;
810

11+
import com.baeldung.abstractclasses.filereaders.BaseFileReader;
12+
import com.baeldung.abstractclasses.filereaders.StandardFileReader;
13+
914
public class StandardFileReaderUnitTest {
1015

1116
@Test
1217
public void givenStandardFileReaderInstance_whenCalledreadFile_thenCorrect() throws Exception {
13-
String filePath = getClass().getClassLoader().getResource("files/test.txt").getPath().substring(1);
18+
// We'll transform the resource URL path to URI to load the file correctly in Windows
19+
URL url = getClass().getClassLoader().getResource("files/test.txt");
20+
String filePath = Paths.get(url.toURI()).toString();
1421
BaseFileReader standardFileReader = new StandardFileReader(filePath);
1522

1623
assertThat(standardFileReader.readFile()).isInstanceOf(List.class);

core-java/src/test/java/com/baeldung/abstractclasses/UppercaseFileReaderUnitTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.baeldung.abstractclasses.filereaders.BaseFileReader;
44
import com.baeldung.abstractclasses.filereaders.UppercaseFileReader;
5+
6+
import java.net.URL;
7+
import java.nio.file.Paths;
58
import java.util.List;
69
import static org.assertj.core.api.Assertions.assertThat;
710
import org.junit.Test;
@@ -10,7 +13,9 @@ public class UppercaseFileReaderUnitTest {
1013

1114
@Test
1215
public void givenUppercaseFileReaderInstance_whenCalledreadFile_thenCorrect() throws Exception {
13-
String filePath = getClass().getClassLoader().getResource("files/test.txt").getPath().substring(1);
16+
// We'll transform the resource URL path to URI to load the file correctly in Windows
17+
URL url = getClass().getClassLoader().getResource("files/test.txt");
18+
String filePath = Paths.get(url.toURI()).toString();
1419
BaseFileReader uppercaseFileReader = new UppercaseFileReader(filePath);
1520

1621
assertThat(uppercaseFileReader.readFile()).isInstanceOf(List.class);

core-java/src/test/java/com/baeldung/simpledateformat/SimpleDateFormatUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void givenSpecificDate_whenFormatted_thenCheckFormatCorrect() throws Exce
2525

2626
@Test
2727
public void givenSpecificDate_whenFormattedUsingDateFormat_thenCheckFormatCorrect() throws Exception {
28-
DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT);
28+
DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
2929
assertEquals("5/24/77", formatter.format(new Date(233345223232L)));
3030
}
3131

0 commit comments

Comments
 (0)