1818import java .nio .file .Files ;
1919import java .nio .file .Path ;
2020import java .nio .file .Paths ;
21+ import java .util .stream .Collectors ;
2122import java .util .stream .Stream ;
2223
2324import static org .junit .Assert .assertEquals ;
@@ -50,7 +51,7 @@ public void givenFileNameAsAbsolutePath_whenUsingClasspath_thenFileData() throws
5051
5152 @ Test
5253 public void givenFileName_whenUsingJarFile_thenFileData () throws IOException {
53- String expectedData = "BSD License" ;
54+ String expectedData = "MIT License" ;
5455
5556 Class clazz = Matchers .class ;
5657 InputStream inputStream = clazz .getResourceAsStream ("/LICENSE.txt" );
@@ -79,7 +80,7 @@ public void givenFileName_whenUsingFileUtils_thenFileData() throws IOException {
7980
8081 ClassLoader classLoader = getClass ().getClassLoader ();
8182 File file = new File (classLoader .getResource ("fileTest.txt" ).getFile ());
82- String data = FileUtils .readFileToString (file );
83+ String data = FileUtils .readFileToString (file , "UTF-8" );
8384
8485 assertEquals (expectedData , data .trim ());
8586 }
@@ -102,12 +103,11 @@ public void givenFilePath_whenUsingFilesLines_thenFileData() throws IOException,
102103
103104 Path path = Paths .get (getClass ().getClassLoader ().getResource ("fileTest.txt" ).toURI ());
104105
105- StringBuilder data = new StringBuilder ();
106106 Stream <String > lines = Files .lines (path );
107- lines . forEach ( line -> data . append ( line ). append ("\n " ));
107+ String data = lines . collect ( Collectors . joining ("\n " ));
108108 lines .close ();
109109
110- assertEquals (expectedData , data .toString (). trim ());
110+ assertEquals (expectedData , data .trim ());
111111 }
112112
113113 private String readFromInputStream (InputStream inputStream ) throws IOException {
0 commit comments