1515import java .net .URISyntaxException ;
1616import java .net .URL ;
1717import java .net .URLConnection ;
18+ import java .nio .charset .Charset ;
1819import java .nio .file .Files ;
1920import java .nio .file .Path ;
2021import java .nio .file .Paths ;
22+ import java .util .stream .Collectors ;
2123import java .util .stream .Stream ;
2224
2325import static org .junit .Assert .assertEquals ;
@@ -50,7 +52,7 @@ public void givenFileNameAsAbsolutePath_whenUsingClasspath_thenFileData() throws
5052
5153 @ Test
5254 public void givenFileName_whenUsingJarFile_thenFileData () throws IOException {
53- String expectedData = "BSD License" ;
55+ String expectedData = "MIT License" ;
5456
5557 Class clazz = Matchers .class ;
5658 InputStream inputStream = clazz .getResourceAsStream ("/LICENSE.txt" );
@@ -79,7 +81,7 @@ public void givenFileName_whenUsingFileUtils_thenFileData() throws IOException {
7981
8082 ClassLoader classLoader = getClass ().getClassLoader ();
8183 File file = new File (classLoader .getResource ("fileTest.txt" ).getFile ());
82- String data = FileUtils .readFileToString (file );
84+ String data = FileUtils .readFileToString (file , "UTF-8" );
8385
8486 assertEquals (expectedData , data .trim ());
8587 }
@@ -102,12 +104,11 @@ public void givenFilePath_whenUsingFilesLines_thenFileData() throws IOException,
102104
103105 Path path = Paths .get (getClass ().getClassLoader ().getResource ("fileTest.txt" ).toURI ());
104106
105- StringBuilder data = new StringBuilder ();
106107 Stream <String > lines = Files .lines (path );
107- lines . forEach ( line -> data . append ( line ). append ("\n " ));
108+ String data = lines . collect ( Collectors . joining ("\n " ));
108109 lines .close ();
109110
110- assertEquals (expectedData , data .toString (). trim ());
111+ assertEquals (expectedData , data .trim ());
111112 }
112113
113114 private String readFromInputStream (InputStream inputStream ) throws IOException {
0 commit comments