20
20
import static org .powermock .api .mockito .PowerMockito .when ;
21
21
import java .io .File ;
22
22
import java .io .FileNotFoundException ;
23
+ import java .io .IOException ;
23
24
import java .util .LinkedHashMap ;
24
25
import java .util .Map ;
25
26
import org .apache .commons .io .FileUtils ;
26
27
import org .apache .commons .lang3 .reflect .FieldUtils ;
27
28
import org .junit .Before ;
29
+ import org .junit .Ignore ;
28
30
import org .junit .Test ;
29
31
import org .junit .runner .RunWith ;
30
32
import org .mockito .Mock ;
@@ -40,15 +42,13 @@ public class LessSourceTest {
40
42
private LessSource lessSource ;
41
43
42
44
@ Mock private File file ;
43
-
45
+
44
46
@ Mock private LessSource import1 ;
45
47
@ Mock private LessSource import2 ;
46
48
@ Mock private LessSource import3 ;
47
49
48
50
private Map <String , LessSource > imports ;
49
-
50
- private String content = "content" ;
51
- private String absolutePath = "path" ;
51
+
52
52
private long lastModified = 1l ;
53
53
54
54
@ Before
@@ -61,17 +61,13 @@ public void setUp() throws Exception {
61
61
62
62
@ Test
63
63
public void testNewLessSourceWithoutImports () throws Exception {
64
- when (file .exists ()).thenReturn (true );
65
- mockStatic (FileUtils .class );
66
- when (FileUtils .readFileToString (file )).thenReturn (content );
67
- when (file .getAbsolutePath ()).thenReturn (absolutePath );
68
- when (file .lastModified ()).thenReturn (lastModified );
64
+ mockFile (true ,"content" ,"absolutePath" );
69
65
70
66
lessSource = new LessSource (file );
71
67
72
- assertEquals (absolutePath , lessSource .getAbsolutePath ());
73
- assertEquals (content , lessSource .getContent ());
74
- assertEquals (content , lessSource .getNormalizedContent ());
68
+ assertEquals (" absolutePath" , lessSource .getAbsolutePath ());
69
+ assertEquals (" content" , lessSource .getContent ());
70
+ assertEquals (" content" , lessSource .getNormalizedContent ());
75
71
assertEquals (lastModified , lessSource .getLastModified ());
76
72
assertEquals (lastModified , lessSource .getLastModifiedIncludingImports ());
77
73
assertEquals (0 , lessSource .getImports ().size ());
@@ -93,11 +89,7 @@ public void testNewLessSourceFileNotFound() throws Exception {
93
89
94
90
@ Test
95
91
public void testLastModifiedIncludingImportsWhenNoImportModifiedLater () throws Exception {
96
- when (file .exists ()).thenReturn (true );
97
- mockStatic (FileUtils .class );
98
- when (FileUtils .readFileToString (file )).thenReturn (content );
99
- when (file .getAbsolutePath ()).thenReturn (absolutePath );
100
- when (file .lastModified ()).thenReturn (1l );
92
+ mockFile (true ,"content" ,"absolutePath" );
101
93
102
94
when (import1 .getLastModifiedIncludingImports ()).thenReturn (0l );
103
95
when (import2 .getLastModifiedIncludingImports ()).thenReturn (0l );
@@ -111,11 +103,7 @@ public void testLastModifiedIncludingImportsWhenNoImportModifiedLater() throws E
111
103
112
104
@ Test
113
105
public void testLastModifiedIncludingImportsWhenImportModifiedLater () throws Exception {
114
- when (file .exists ()).thenReturn (true );
115
- mockStatic (FileUtils .class );
116
- when (FileUtils .readFileToString (file )).thenReturn (content );
117
- when (file .getAbsolutePath ()).thenReturn (absolutePath );
118
- when (file .lastModified ()).thenReturn (1l );
106
+ mockFile (true ,"content" ,"absolutePath" );
119
107
120
108
when (import1 .getLastModifiedIncludingImports ()).thenReturn (0l );
121
109
when (import2 .getLastModifiedIncludingImports ()).thenReturn (2l );
@@ -126,4 +114,14 @@ public void testLastModifiedIncludingImportsWhenImportModifiedLater() throws Exc
126
114
127
115
assertEquals (2l , lessSource .getLastModifiedIncludingImports ());
128
116
}
117
+
118
+ private File mockFile (boolean fileExists , String content , String absolutePath ) throws IOException {
119
+ when (file .exists ()).thenReturn (fileExists );
120
+ mockStatic (FileUtils .class );
121
+ when (FileUtils .readFileToString (file )).thenReturn (content );
122
+ when (file .getAbsolutePath ()).thenReturn (absolutePath );
123
+ when (file .lastModified ()).thenReturn (lastModified );
124
+ when (file .getParent ()).thenReturn ("folder" );
125
+ return file ;
126
+ }
129
127
}
0 commit comments