2828
2929public class WorkDirTest {
3030
31+ public static Path TEST_DIR ;
32+
3133 @ BeforeClass
3234 public static void setup () {
33- Path tempDir = Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" );
35+ TEST_DIR = Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" );
3436 try {
35- Files .createDirectories (tempDir );
37+ Files .createDirectories (TEST_DIR );
3638 } catch (Exception e ) {
3739 fail (e .toString ());
3840 }
3941 try {
40- Files .createDirectories (tempDir .resolve ("viikko1-teht1" ).resolve ("src" ));
42+ Files .createDirectories (TEST_DIR .resolve ("viikko1-teht1" ).resolve ("src" ));
4143 } catch (Exception e ) {
4244 fail (e .toString ());
4345 }
4446 try {
45- Files .createDirectories (tempDir .resolve ("viikko2-teht2" ).resolve ("src" ));
47+ Files .createDirectories (TEST_DIR .resolve ("viikko2-teht2" ).resolve ("src" ));
4648 } catch (Exception e ) {
4749 fail (e .toString ());
4850 }
4951 try {
50- Files .createDirectories (tempDir .resolve ("viikko2-teht3" ).resolve ("src" ));
52+ Files .createDirectories (TEST_DIR .resolve ("viikko2-teht3" ).resolve ("src" ));
5153 } catch (Exception e ) {
5254 fail (e .toString ());
5355 }
@@ -60,14 +62,13 @@ public static void setup() {
6062 CourseInfo info = new CourseInfo (new Account (), new Course ("dirUtilTest" ));
6163 info .getLocalCompletedExercises ().add ("viikko1-teht1" );
6264 info .setExercises (exercises );
63- CourseInfoIo .save (info , tempDir .resolve (CourseInfoIo .COURSE_CONFIG ));
65+ CourseInfoIo .save (info , TEST_DIR .resolve (CourseInfoIo .COURSE_CONFIG ));
6466 }
6567
6668 @ AfterClass
6769 public static void cleanUp () {
68- String tempDir = System .getProperty ("java.io.tmpdir" );
6970 try {
70- FileUtils .deleteDirectory (Paths . get ( tempDir ). resolve ( "dirUtilTest" ) .toFile ());
71+ FileUtils .deleteDirectory (TEST_DIR .toFile ());
7172 } catch (Exception e ) { }
7273 }
7374
@@ -82,9 +83,8 @@ public void getsCorrectWorkingDirectory() {
8283 @ Test
8384 public void overridingWorkingDirectoryWorks () {
8485 WorkDir workDir = new WorkDir ();
85- workDir .setWorkdir (Paths .get (System .getProperty ("java.io.tmpdir" )));
86- assertEquals (Paths .get (System .getProperty ("java.io.tmpdir" )),
87- workDir .getWorkingDirectory ());
86+ workDir .setWorkdir (TEST_DIR );
87+ assertEquals (TEST_DIR , workDir .getWorkingDirectory ());
8888 }
8989
9090 @ Test
@@ -99,48 +99,34 @@ public void failsIfNotInCourseDirectory() {
9999 @ Test
100100 public void absolutePathsWork () {
101101 WorkDir workDir = new WorkDir ();
102- workDir .addPath (Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" ));
103- assertEquals (Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" ),
104- workDir .getCourseDirectory ());
105- assertEquals (Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" )
106- .resolve (CourseInfoIo .COURSE_CONFIG ),
102+ workDir .addPath (TEST_DIR );
103+ assertEquals (TEST_DIR , workDir .getCourseDirectory ());
104+ assertEquals (TEST_DIR .resolve (CourseInfoIo .COURSE_CONFIG ),
107105 workDir .getConfigFile ());
108106 }
109107
110108 @ Test
111109 public void returnsCorrectValuesInCourseDirectory () {
112110 WorkDir workDir = new WorkDir ();
113- workDir .setWorkdir (Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" ));
114- assertEquals ("Course dir is correct" ,
115- Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" ),
111+ workDir .setWorkdir (TEST_DIR );
112+ assertEquals ("Course dir is correct" , TEST_DIR ,
116113 workDir .getCourseDirectory ());
117- assertEquals ("Working dir is correct" ,
118- Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" ),
114+ assertEquals ("Working dir is correct" , TEST_DIR ,
119115 workDir .getWorkingDirectory ());
120116 }
121117
122118 @ Test
123119 public void returnsCorrectValuesInExerciseDirectory () {
124- Path tempDir = Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" );
125120 WorkDir workDir = new WorkDir ();
126- workDir .setWorkdir (tempDir .resolve ("viikko1-teht1" ));
127- assertEquals (
128- Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" ),
129- workDir .getCourseDirectory ());
130- assertEquals (
131- Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" )
132- .resolve ("viikko1-teht1" ),
133- workDir .getWorkingDirectory ());
121+ workDir .setWorkdir (TEST_DIR .resolve ("viikko1-teht1" ));
122+ assertEquals (TEST_DIR , workDir .getCourseDirectory ());
134123 }
135124
136125 @ Test
137126 public void worksIfInCourseDirectoryWithNoParams () {
138- Path tempDir = Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" );
139127 WorkDir workDir = new WorkDir ();
140- workDir .setWorkdir (tempDir );
141- assertEquals (
142- Paths .get (System .getProperty ("java.io.tmpdir" ))
143- .resolve ("dirUtilTest" ).resolve (CourseInfoIo .COURSE_CONFIG ),
128+ workDir .setWorkdir (TEST_DIR );
129+ assertEquals (TEST_DIR .resolve (CourseInfoIo .COURSE_CONFIG ),
144130 workDir .getConfigFile ());
145131 List <String > exercises = workDir .getExerciseNames (true , false , false );
146132 assertEquals (3 , exercises .size ());
@@ -152,22 +138,15 @@ public void worksIfInCourseDirectoryWithNoParams() {
152138 @ Test
153139 public void worksIfCourseDirectoryIsGivenAsAParameter () {
154140 WorkDir workDir = new WorkDir ();
155- workDir .addPath (Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" ));
156- assertEquals (Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" ),
157- workDir .getCourseDirectory ());
158- assertEquals (Paths .get (System .getProperty ("java.io.tmpdir" ))
159- .resolve ("dirUtilTest" ), workDir .getWorkingDirectory ());
141+ workDir .addPath (TEST_DIR );
142+ assertEquals (TEST_DIR , workDir .getCourseDirectory ());
160143 }
161144
162145 @ Test
163146 public void worksIfInExerciseDirectoryWithNoParams () {
164- Path tempDir = Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" )
165- .resolve ("viikko2-teht2" );
166147 WorkDir workDir = new WorkDir ();
167- workDir .setWorkdir (tempDir );
168- assertEquals (
169- Paths .get (System .getProperty ("java.io.tmpdir" ))
170- .resolve ("dirUtilTest" ).resolve (CourseInfoIo .COURSE_CONFIG ),
148+ workDir .setWorkdir (TEST_DIR .resolve ("viikko2-teht2" ));
149+ assertEquals (TEST_DIR .resolve (CourseInfoIo .COURSE_CONFIG ),
171150 workDir .getConfigFile ());
172151 List <String > exercises = workDir .getExerciseNames (true , false , false );
173152 assertEquals (1 , exercises .size ());
@@ -179,13 +158,9 @@ public void worksIfInExerciseDirectoryWithNoParams() {
179158 @ Ignore // Obsolete functionality
180159 @ Test
181160 public void worksIfInSubSubDirectoryWithNoParams () {
182- Path tempDir = Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" )
183- .resolve ("viikko2" ).resolve ("subdir" );
184161 WorkDir workDir = new WorkDir ();
185- workDir .setWorkdir (tempDir );
186- assertEquals (
187- Paths .get (System .getProperty ("java.io.tmpdir" ))
188- .resolve ("dirUtilTest" ).resolve (CourseInfoIo .COURSE_CONFIG ),
162+ workDir .setWorkdir (TEST_DIR .resolve ("viikko2" ).resolve ("subdir" ));
163+ assertEquals (TEST_DIR .resolve (CourseInfoIo .COURSE_CONFIG ),
189164 workDir .getConfigFile ());
190165 List <String > exercises = workDir .getExerciseNames (true , false , false );
191166 assertEquals (1 , exercises .size ());
@@ -196,22 +171,19 @@ public void worksIfInSubSubDirectoryWithNoParams() {
196171
197172 @ Test
198173 public void worksIfInCourseDirectoryWithParams () {
199- Path tempDir = Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" );
200174 WorkDir workDir = new WorkDir ();
201- workDir .setWorkdir (tempDir );
175+ workDir .setWorkdir (TEST_DIR );
202176 workDir .addPath ("viikko2-teht2" );
203177 workDir .addPath ("viikko2-teht3" );
204- assertEquals (
205- Paths .get (System .getProperty ("java.io.tmpdir" ))
206- .resolve ("dirUtilTest" ).resolve (CourseInfoIo .COURSE_CONFIG ),
178+ assertEquals (TEST_DIR .resolve (CourseInfoIo .COURSE_CONFIG ),
207179 workDir .getConfigFile ());
208180 List <String > exercises = workDir .getExerciseNames ();
209181 assertEquals (2 , exercises .size ());
210182 assertFalse (exercises .contains ("viikko1-teht1" ));
211183 assertTrue (exercises .contains ("viikko2-teht2" ));
212184 assertTrue (exercises .contains ("viikko2-teht3" ));
213185 workDir = new WorkDir ();
214- workDir .setWorkdir (tempDir );
186+ workDir .setWorkdir (TEST_DIR );
215187 workDir .addPath ("teht1" );
216188 exercises = workDir .getExerciseNames (true , false , false );
217189 assertEquals (0 , exercises .size ());
@@ -223,13 +195,9 @@ public void worksIfInCourseDirectoryWithParams() {
223195 @ Ignore // Obsolete functionality
224196 @ Test
225197 public void worksIfInSubDirectoryWithParams () {
226- Path tempDir = Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" )
227- .resolve ("viikko2" );
228198 WorkDir workDir = new WorkDir ();
229- workDir .setWorkdir (tempDir );
230- assertEquals (
231- Paths .get (System .getProperty ("java.io.tmpdir" ))
232- .resolve ("dirUtilTest" ).resolve (CourseInfoIo .COURSE_CONFIG ),
199+ workDir .setWorkdir (TEST_DIR .resolve ("viikko2" ));
200+ assertEquals (TEST_DIR .resolve (CourseInfoIo .COURSE_CONFIG ),
233201 workDir .getConfigFile ());
234202 workDir .addPath ("teht2" );
235203 List <String > exercises = workDir .getExerciseNames (true , false , false );
@@ -242,10 +210,8 @@ public void worksIfInSubDirectoryWithParams() {
242210 @ Ignore // Obsolete functionality
243211 @ Test
244212 public void worksIfInSubSubDirectoryWithParams () {
245- Path tempDir = Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" )
246- .resolve ("viikko2" ).resolve ("subdir" );
247213 WorkDir workDir = new WorkDir ();
248- workDir .setWorkdir (tempDir );
214+ workDir .setWorkdir (TEST_DIR . resolve ( "viikko2" ). resolve ( "subdir" ) );
249215 assertEquals (
250216 Paths .get (System .getProperty ("java.io.tmpdir" ))
251217 .resolve ("dirUtilTest" ).resolve (CourseInfoIo .COURSE_CONFIG ),
@@ -260,8 +226,7 @@ public void worksIfInSubSubDirectoryWithParams() {
260226
261227 @ Test
262228 public void worksInSubDirectoryOfAnExercise () {
263- Path path = Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" )
264- .resolve ("viikko1-teht1" ).resolve ("src" );
229+ Path path = TEST_DIR .resolve ("viikko1-teht1" ).resolve ("src" );
265230 WorkDir workDir = new WorkDir ();
266231 workDir .addPath (path );
267232 List <String > exercises = workDir .getExerciseNames (true , false , false );
@@ -273,9 +238,8 @@ public void worksInSubDirectoryOfAnExercise() {
273238
274239 @ Test
275240 public void worksWhenDeletedExercisesAreNotFiltered () {
276- Path path = Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" );
277241 WorkDir workDir = new WorkDir ();
278- workDir .addPath (path );
242+ workDir .addPath (TEST_DIR );
279243 List <String > exercises = workDir .getExerciseNames (false , false , false );
280244 assertEquals (4 , exercises .size ());
281245 assertTrue (exercises .contains ("viikko1-teht1" ));
@@ -286,9 +250,8 @@ public void worksWhenDeletedExercisesAreNotFiltered() {
286250
287251 @ Test
288252 public void filteringCompletedExercisesWorks () {
289- Path path = Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" );
290253 WorkDir workDir = new WorkDir ();
291- workDir .addPath (path );
254+ workDir .addPath (TEST_DIR );
292255 List <String > exercises = workDir .getExerciseNames (false , false , true );
293256 assertEquals (3 , exercises .size ());
294257 assertTrue (exercises .contains ("viikko1-teht1" ));
@@ -299,9 +262,8 @@ public void filteringCompletedExercisesWorks() {
299262
300263 @ Test
301264 public void filteringOnlyTestedExercisesWorks () {
302- Path path = Paths .get (System .getProperty ("java.io.tmpdir" )).resolve ("dirUtilTest" );
303265 WorkDir workDir = new WorkDir ();
304- workDir .addPath (path );
266+ workDir .addPath (TEST_DIR );
305267 List <String > exercises = workDir .getExerciseNames (false , true , false );
306268 assertEquals (1 , exercises .size ());
307269 assertTrue (exercises .contains ("viikko1-teht1" ));
0 commit comments