18
18
*/
19
19
20
20
/*
21
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
21
+ * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
22
22
* Portions Copyright (c) 2020, Aleksandr Kirillov <[email protected] >.
23
23
*/
24
24
package org .opengrok .indexer .configuration ;
25
25
26
- import java .io .BufferedWriter ;
27
- import java .io .File ;
28
- import java .io .FileWriter ;
29
26
import java .io .IOException ;
27
+ import java .nio .charset .Charset ;
30
28
import java .nio .file .Files ;
31
29
import java .nio .file .Path ;
32
30
import org .junit .BeforeClass ;
@@ -44,72 +42,59 @@ public class IncludeFilesTest {
44
42
static final String CONTENT_1 = "foo" ;
45
43
static final String CONTENT_2 = "bar" ;
46
44
static RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
47
- static final String LINE_SEP = System .lineSeparator ();
48
-
45
+
49
46
@ BeforeClass
50
47
public static void setUpClass () throws IOException {
51
48
includeRoot = Files .createTempDirectory ("include_root" );
52
49
env .setIncludeRoot (includeRoot .toString ());
53
50
}
54
-
55
- private void writeStringToFile (File file , String str ) throws IOException {
56
- try (BufferedWriter bw = new BufferedWriter (new FileWriter (file ))) {
57
- bw .write (str );
58
- }
51
+
52
+ private void writeStringToFile (Path file , String str ) throws IOException {
53
+ Files .writeString (file , str , Charset .defaultCharset ());
59
54
}
60
-
55
+
61
56
@ Test
62
57
public void testGetHeaderIncludeFileContent () throws IOException {
63
- File file = new File ( includeRoot .toFile (), Configuration .HEADER_INCLUDE_FILE );
58
+ Path file = includeRoot .resolve ( Configuration .HEADER_INCLUDE_FILE );
64
59
writeStringToFile (file , CONTENT_1 );
65
- assertEquals (CONTENT_1 + LINE_SEP ,
66
- env .includeFiles .getHeaderIncludeFileContent (false ));
60
+ assertEquals (CONTENT_1 , env .includeFiles .getHeaderIncludeFileContent (false ));
67
61
writeStringToFile (file , CONTENT_2 );
68
- assertEquals (CONTENT_2 + LINE_SEP ,
69
- env .includeFiles .getHeaderIncludeFileContent (true ));
62
+ assertEquals (CONTENT_2 , env .includeFiles .getHeaderIncludeFileContent (true ));
70
63
}
71
-
64
+
72
65
@ Test
73
66
public void testGetBodyIncludeFileContent () throws IOException {
74
- File file = new File ( includeRoot .toFile (), Configuration .BODY_INCLUDE_FILE );
67
+ Path file = includeRoot .resolve ( Configuration .BODY_INCLUDE_FILE );
75
68
writeStringToFile (file , CONTENT_1 );
76
- assertEquals (CONTENT_1 + LINE_SEP ,
77
- env .includeFiles .getBodyIncludeFileContent (false ));
69
+ assertEquals (CONTENT_1 , env .includeFiles .getBodyIncludeFileContent (false ));
78
70
writeStringToFile (file , CONTENT_2 );
79
- assertEquals (CONTENT_2 + LINE_SEP ,
80
- env .includeFiles .getBodyIncludeFileContent (true ));
71
+ assertEquals (CONTENT_2 , env .includeFiles .getBodyIncludeFileContent (true ));
81
72
}
82
-
73
+
83
74
@ Test
84
75
public void testGetFooterIncludeFileContent () throws IOException {
85
- File file = new File ( includeRoot .toFile (), Configuration .FOOTER_INCLUDE_FILE );
76
+ Path file = includeRoot .resolve ( Configuration .FOOTER_INCLUDE_FILE );
86
77
writeStringToFile (file , CONTENT_1 );
87
- assertEquals (CONTENT_1 + LINE_SEP ,
88
- env .includeFiles .getFooterIncludeFileContent (false ));
78
+ assertEquals (CONTENT_1 , env .includeFiles .getFooterIncludeFileContent (false ));
89
79
writeStringToFile (file , CONTENT_2 );
90
- assertEquals (CONTENT_2 + LINE_SEP ,
91
- env .includeFiles .getFooterIncludeFileContent (true ));
80
+ assertEquals (CONTENT_2 , env .includeFiles .getFooterIncludeFileContent (true ));
92
81
}
93
-
82
+
94
83
@ Test
95
84
public void testGetForbiddenIncludeFileContent () throws IOException {
96
- File file = new File ( includeRoot .toFile (), Configuration .E_FORBIDDEN_INCLUDE_FILE );
85
+ Path file = includeRoot .resolve ( Configuration .E_FORBIDDEN_INCLUDE_FILE );
97
86
writeStringToFile (file , CONTENT_1 );
98
- assertEquals (CONTENT_1 + LINE_SEP ,
99
- env .includeFiles .getForbiddenIncludeFileContent (false ));
87
+ assertEquals (CONTENT_1 , env .includeFiles .getForbiddenIncludeFileContent (false ));
100
88
writeStringToFile (file , CONTENT_2 );
101
- assertEquals (CONTENT_2 + LINE_SEP ,
102
- env .includeFiles .getForbiddenIncludeFileContent (true ));
89
+ assertEquals (CONTENT_2 , env .includeFiles .getForbiddenIncludeFileContent (true ));
103
90
}
104
91
105
92
@ Test
106
93
public void testGetHttpHeaderIncludeFileContent () throws IOException {
107
- File file = new File ( includeRoot .toFile (), Configuration .HTTP_HEADER_INCLUDE_FILE );
94
+ Path file = includeRoot .resolve ( Configuration .HTTP_HEADER_INCLUDE_FILE );
108
95
writeStringToFile (file , CONTENT_1 );
109
- assertEquals (CONTENT_1 + LINE_SEP ,
110
- env .includeFiles .getHttpHeaderIncludeFileContent (false ));
96
+ assertEquals (CONTENT_1 , env .includeFiles .getHttpHeaderIncludeFileContent (false ));
111
97
writeStringToFile (file , CONTENT_2 );
112
- assertEquals (CONTENT_2 + LINE_SEP ,
113
- env .includeFiles .getHttpHeaderIncludeFileContent (true ));
98
+ assertEquals (CONTENT_2 , env .includeFiles .getHttpHeaderIncludeFileContent (true ));
114
99
}
115
100
}
0 commit comments