File tree Expand file tree Collapse file tree
core-java/src/test/java/com/baeldung Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import com .baeldung .abstractclasses .filereaders .BaseFileReader ;
44import com .baeldung .abstractclasses .filereaders .LowercaseFileReader ;
5+
6+ import java .net .URL ;
7+ import java .nio .file .Paths ;
58import java .util .List ;
69import static org .assertj .core .api .Assertions .assertThat ;
710import org .junit .Test ;
811
912public 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}
Original file line number Diff line number Diff line change 11package com .baeldung .abstractclasses ;
22
3- import com .baeldung .abstractclasses .filereaders .BaseFileReader ;
4- import com .baeldung .abstractclasses .filereaders .StandardFileReader ;
5- import java .util .List ;
63import 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+
79import org .junit .Test ;
810
11+ import com .baeldung .abstractclasses .filereaders .BaseFileReader ;
12+ import com .baeldung .abstractclasses .filereaders .StandardFileReader ;
13+
914public 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 );
Original file line number Diff line number Diff line change 22
33import com .baeldung .abstractclasses .filereaders .BaseFileReader ;
44import com .baeldung .abstractclasses .filereaders .UppercaseFileReader ;
5+
6+ import java .net .URL ;
7+ import java .nio .file .Paths ;
58import java .util .List ;
69import static org .assertj .core .api .Assertions .assertThat ;
710import 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 );
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments