18
18
*/
19
19
20
20
/*
21
- * Copyright (c) 2008, 2017 , Oracle and/or its affiliates. All rights reserved.
21
+ * Copyright (c) 2008, 2018 , Oracle and/or its affiliates. All rights reserved.
22
22
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected] >.
23
23
*/
24
24
package org .opensolaris .opengrok .configuration ;
32
32
import java .net .InetSocketAddress ;
33
33
import java .net .SocketAddress ;
34
34
import java .nio .file .Files ;
35
- import java .nio .file .Paths ;
35
+ import java .nio .file .Path ;
36
36
import java .util .ArrayList ;
37
37
import java .util .Arrays ;
38
38
import java .util .Date ;
43
43
import java .util .regex .PatternSyntaxException ;
44
44
import org .apache .tools .ant .filters .StringInputStream ;
45
45
import org .json .simple .parser .ParseException ;
46
- import org .junit .After ;
47
46
import org .junit .AfterClass ;
48
47
import org .junit .Assert ;
49
48
import org .junit .Before ;
65
64
import static org .junit .Assert .assertSame ;
66
65
import static org .junit .Assert .assertTrue ;
67
66
import static org .junit .Assert .fail ;
68
- import org .opensolaris .opengrok .util .FileUtilities ;
69
67
import org .opensolaris .opengrok .util .ForbiddenSymlinkException ;
70
68
import org .opensolaris .opengrok .util .IOUtils ;
71
69
@@ -97,16 +95,12 @@ public static void tearDownClass() throws Exception {
97
95
}
98
96
99
97
@ Before
100
- public void setUp () throws IOException {
98
+ public void setUp () {
101
99
// Create a default configuration
102
100
Configuration config = new Configuration ();
103
101
RuntimeEnvironment .getInstance ().setConfiguration (config );
104
102
}
105
103
106
- @ After
107
- public void tearDown () throws IOException {
108
- }
109
-
110
104
@ Test
111
105
public void testDataRoot () throws IOException {
112
106
RuntimeEnvironment instance = RuntimeEnvironment .getInstance ();
@@ -160,7 +154,7 @@ public void testProjects() throws IOException {
160
154
}
161
155
162
156
@ Test
163
- public void testGroups () throws IOException {
157
+ public void testGroups () {
164
158
RuntimeEnvironment instance = RuntimeEnvironment .getInstance ();
165
159
assertFalse (instance .hasGroups ());
166
160
assertNotNull (instance .getGroups ());
@@ -178,18 +172,14 @@ public void testGroups() throws IOException {
178
172
}
179
173
180
174
@ Test
181
- public void testRegister () throws InterruptedException , IOException {
175
+ public void testRegister () throws InterruptedException {
182
176
RuntimeEnvironment instance = RuntimeEnvironment .getInstance ();
183
177
String path = "/tmp/dataroot" ;
184
178
instance .setDataRoot (path );
185
179
instance .register ();
186
- Thread t = new Thread (new Runnable () {
187
-
188
- public void run () {
189
- Configuration c = new Configuration ();
190
- RuntimeEnvironment .getInstance ().setConfiguration (c );
191
-
192
- }
180
+ Thread t = new Thread (() -> {
181
+ Configuration c = new Configuration ();
182
+ RuntimeEnvironment .getInstance ().setConfiguration (c );
193
183
});
194
184
t .start ();
195
185
t .join ();
@@ -232,17 +222,17 @@ public void testHistoryReaderTimeLimit() {
232
222
@ Test
233
223
public void testFetchHistoryWhenNotInCache () {
234
224
RuntimeEnvironment instance = RuntimeEnvironment .getInstance ();
235
- assertEquals ( true , instance .isFetchHistoryWhenNotInCache ());
225
+ assertTrue ( instance .isFetchHistoryWhenNotInCache ());
236
226
instance .setFetchHistoryWhenNotInCache (false );
237
- assertEquals ( false , instance .isFetchHistoryWhenNotInCache ());
227
+ assertFalse ( instance .isFetchHistoryWhenNotInCache ());
238
228
}
239
229
240
230
@ Test
241
231
public void testUseHistoryCache () {
242
232
RuntimeEnvironment instance = RuntimeEnvironment .getInstance ();
243
- assertEquals ( true , instance .useHistoryCache ());
233
+ assertTrue ( instance .useHistoryCache ());
244
234
instance .setUseHistoryCache (false );
245
- assertEquals ( false , instance .useHistoryCache ());
235
+ assertFalse ( instance .useHistoryCache ());
246
236
}
247
237
248
238
@ Test
@@ -1052,13 +1042,13 @@ public void testSaveStatistics() throws IOException {
1052
1042
}
1053
1043
1054
1044
@ Test (expected = IOException .class )
1055
- public void testSaveNullStatistics () throws IOException , ParseException {
1045
+ public void testSaveNullStatistics () throws IOException {
1056
1046
RuntimeEnvironment .getInstance ().getConfiguration ().setStatisticsFilePath (null );
1057
1047
RuntimeEnvironment .getInstance ().saveStatistics ();
1058
1048
}
1059
1049
1060
1050
@ Test (expected = IOException .class )
1061
- public void testSaveNullStatisticsFile () throws IOException , ParseException {
1051
+ public void testSaveNullStatisticsFile () throws IOException {
1062
1052
RuntimeEnvironment .getInstance ().saveStatistics ((File ) null );
1063
1053
}
1064
1054
@@ -1085,7 +1075,7 @@ public void testGetPathRelativeToSourceRoot() throws IOException,
1085
1075
RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
1086
1076
1087
1077
// Create and set source root.
1088
- File sourceRoot = FileUtilities . createTemporaryDirectory ("src" );
1078
+ File sourceRoot = Files . createTempDirectory ("src" ). toFile ( );
1089
1079
assertTrue (sourceRoot .exists ());
1090
1080
assertTrue (sourceRoot .isDirectory ());
1091
1081
env .setSourceRoot (sourceRoot .getPath ());
@@ -1100,11 +1090,9 @@ public void testGetPathRelativeToSourceRoot() throws IOException,
1100
1090
1101
1091
// Create symlink underneath source root.
1102
1092
String symlinkName = "symlink" ;
1103
- File realDir = FileUtilities . createTemporaryDirectory ("realdir" );
1093
+ Path realDir = Files . createTempDirectory ("realdir" );
1104
1094
File symlink = new File (sourceRoot , symlinkName );
1105
- Files .createSymbolicLink (
1106
- Paths .get (symlink .getPath ()),
1107
- Paths .get (realDir .getPath ()));
1095
+ Files .createSymbolicLink (symlink .toPath (), realDir );
1108
1096
assertTrue (symlink .exists ());
1109
1097
env .setAllowedSymlinks (new HashSet <>());
1110
1098
ForbiddenSymlinkException expex = null ;
@@ -1113,8 +1101,8 @@ public void testGetPathRelativeToSourceRoot() throws IOException,
1113
1101
} catch (ForbiddenSymlinkException e ) {
1114
1102
expex = e ;
1115
1103
}
1116
- assertTrue ("getPathRelativeToSourceRoot() should have thrown " +
1117
- "IOexception for symlink that is not allowed" , expex != null );
1104
+ assertNotNull ("getPathRelativeToSourceRoot() should have thrown " +
1105
+ "IOexception for symlink that is not allowed" , expex );
1118
1106
1119
1107
// Allow the symlink and retest.
1120
1108
env .setAllowedSymlinks (new HashSet <>(Arrays .asList (symlink .getPath ())));
@@ -1123,6 +1111,6 @@ public void testGetPathRelativeToSourceRoot() throws IOException,
1123
1111
1124
1112
// cleanup
1125
1113
IOUtils .removeRecursive (sourceRoot .toPath ());
1126
- IOUtils .removeRecursive (realDir . toPath () );
1114
+ IOUtils .removeRecursive (realDir );
1127
1115
}
1128
1116
}
0 commit comments