9
9
import org .mockito .Mock ;
10
10
import org .mockito .junit .MockitoJUnitRunner ;
11
11
12
- import java .io .File ;
13
- import java .io .FileWriter ;
14
- import java .io .IOException ;
12
+ import java .io .*;
15
13
import java .util .Arrays ;
16
14
import java .util .List ;
17
15
@@ -27,6 +25,8 @@ public class CurrentVersionTest {
27
25
28
26
@ Mock private ProcessHelper processHelper ;
29
27
28
+ @ Mock private PrintStream mockedLogger ;
29
+
30
30
@ Test
31
31
public void testMavenProjectVersion () throws IOException , InterruptedException {
32
32
@@ -63,7 +63,7 @@ public void testMavenProjectVersion() throws IOException, InterruptedException {
63
63
CurrentVersion currentVersion = new CurrentVersion ();
64
64
currentVersion .setProcessHelper (processHelper );
65
65
66
- Version testCurrentVersion = currentVersion .getCurrentVersion (mavenDir , "" );
66
+ Version testCurrentVersion = currentVersion .getCurrentVersion (mavenDir , "" , mockedLogger );
67
67
68
68
assertThat (testCurrentVersion , is (notNullValue ()));
69
69
assertThat (actualCurrentVersion , is (testCurrentVersion ));
@@ -105,7 +105,7 @@ public void testGradleProjectVersion() throws IOException, InterruptedException
105
105
CurrentVersion currentVersion = new CurrentVersion ();
106
106
currentVersion .setProcessHelper (processHelper );
107
107
108
- Version testCurrentVersion = currentVersion .getCurrentVersion (gradleDir , "" );
108
+ Version testCurrentVersion = currentVersion .getCurrentVersion (gradleDir , "" , mockedLogger );
109
109
110
110
assertThat (testCurrentVersion , is (notNullValue ()));
111
111
assertThat (actualCurrentVersion , is (testCurrentVersion ));
@@ -126,7 +126,7 @@ public void testMakeProjectVersion() throws IOException, InterruptedException {
126
126
127
127
Version actualCurrentVersion = Version .valueOf ("1.10.0" );
128
128
CurrentVersion currentVersion = new CurrentVersion ();
129
- Version testCurrentVersion = currentVersion .getCurrentVersion (makeDir , "" );
129
+ Version testCurrentVersion = currentVersion .getCurrentVersion (makeDir , "" , mockedLogger );
130
130
131
131
assertThat (testCurrentVersion , is (notNullValue ()));
132
132
assertThat (actualCurrentVersion , is (testCurrentVersion ));
@@ -149,7 +149,7 @@ public void testNpmProjectVersion() throws IOException, InterruptedException {
149
149
150
150
Version actualCurrentVersion = Version .valueOf ("1.0.0" );
151
151
CurrentVersion currentVersion = new CurrentVersion ();
152
- Version testCurrentVersion = currentVersion .getCurrentVersion (npmDir , "" );
152
+ Version testCurrentVersion = currentVersion .getCurrentVersion (npmDir , "" , mockedLogger );
153
153
154
154
assertThat (testCurrentVersion , is (notNullValue ()));
155
155
assertThat (actualCurrentVersion , is (testCurrentVersion ));
@@ -191,7 +191,7 @@ public void testPythonProjectVersionSetupPyExists() throws IOException, Interrup
191
191
CurrentVersion currentVersion = new CurrentVersion ();
192
192
currentVersion .setProcessHelper (processHelper );
193
193
194
- Version testCurrentVersion = currentVersion .getCurrentVersion (pyDir , "" );
194
+ Version testCurrentVersion = currentVersion .getCurrentVersion (pyDir , "" , mockedLogger );
195
195
196
196
assertThat (testCurrentVersion , is (notNullValue ()));
197
197
assertThat (actualCurrentVersion , is (testCurrentVersion ));
@@ -212,7 +212,7 @@ public void testPythonProjectVersionSetupCfgExists() throws IOException, Interru
212
212
213
213
Version actualCurrentVersion = Version .valueOf ("0.1.0" );
214
214
CurrentVersion currentVersion = new CurrentVersion ();
215
- Version testCurrentVersion = currentVersion .getCurrentVersion (pyDir , "" );
215
+ Version testCurrentVersion = currentVersion .getCurrentVersion (pyDir , "" , mockedLogger );
216
216
217
217
assertThat (testCurrentVersion , is (notNullValue ()));
218
218
assertThat (actualCurrentVersion , is (testCurrentVersion ));
@@ -241,7 +241,7 @@ public void shouldReadHelmChartCurrentVersion() throws IOException, InterruptedE
241
241
242
242
Version actualCurrentVersion = Version .valueOf ("1.0.0" );
243
243
CurrentVersion currentVersion = new CurrentVersion ();
244
- Version testCurrentVersion = currentVersion .getCurrentVersion (helmDir , "" );
244
+ Version testCurrentVersion = currentVersion .getCurrentVersion (helmDir , "" , mockedLogger );
245
245
assertThat (testCurrentVersion , is (notNullValue ()));
246
246
assertThat (actualCurrentVersion , is (testCurrentVersion ));
247
247
}
@@ -266,7 +266,7 @@ public void testPythonProjectVersionPyProjectTOMLExists()
266
266
267
267
Version actualCurrentVersion = Version .valueOf ("1.0.0" );
268
268
CurrentVersion currentVersion = new CurrentVersion ();
269
- Version testCurrentVersion = currentVersion .getCurrentVersion (pyDir , "" );
269
+ Version testCurrentVersion = currentVersion .getCurrentVersion (pyDir , "" , mockedLogger );
270
270
271
271
assertThat (testCurrentVersion , is (notNullValue ()));
272
272
assertThat (actualCurrentVersion , is (testCurrentVersion ));
@@ -279,7 +279,7 @@ public void CurrentVersion_NoProjectWithTag() throws IOException, InterruptedExc
279
279
Version actualCurrentVersion = Version .valueOf ("0.1.0" );
280
280
281
281
CurrentVersion currentVersion = new CurrentVersion ();
282
- Version testCurrentVersion = currentVersion .getCurrentVersion (testDir , "0.1.0" );
282
+ Version testCurrentVersion = currentVersion .getCurrentVersion (testDir , "0.1.0" , mockedLogger );
283
283
284
284
assertThat (testCurrentVersion , is (notNullValue ()));
285
285
assertThat (actualCurrentVersion , is (testCurrentVersion ));
@@ -292,9 +292,43 @@ public void CurrentVersion_NoProjectNoTag() throws IOException, InterruptedExcep
292
292
Version actualCurrentVersion = Version .valueOf ("0.0.0" );
293
293
294
294
CurrentVersion currentVersion = new CurrentVersion ();
295
- Version testCurrentVersion = currentVersion .getCurrentVersion (testDir , "" );
295
+ Version testCurrentVersion = currentVersion .getCurrentVersion (testDir , "" , mockedLogger );
296
296
297
297
assertThat (testCurrentVersion , is (notNullValue ()));
298
298
assertThat (actualCurrentVersion , is (testCurrentVersion ));
299
299
}
300
+
301
+ @ Test
302
+ public void CurrentVersionMismatchWithTag () throws IOException , InterruptedException {
303
+
304
+ File testDir = rootFolder .newFolder ("SampleProject" );
305
+ Version actualCurrentVersion = Version .valueOf ("0.3.0" );
306
+
307
+ CurrentVersion currentVersion = new CurrentVersion ();
308
+ Version testCurrentVersion = currentVersion .getCurrentVersion (testDir , "0.3.0" , mockedLogger );
309
+
310
+ assertThat (testCurrentVersion , is (notNullValue ()));
311
+ assertThat (testCurrentVersion , is (actualCurrentVersion ));
312
+ }
313
+
314
+ @ Test
315
+ public void testPythonProjectVersionMismatchWithTag () throws IOException , InterruptedException {
316
+
317
+ File pyDir = rootFolder .newFolder ("SamplePythonProject" );
318
+ File setupCfg = rootFolder .newFile (pyDir .getName () + File .separator + "setup.cfg" );
319
+
320
+ String setupCfgContent =
321
+ "[metadata]\n " + "name = sample\n " + "version = 0.1.0\n " + "author = Sample Author" ;
322
+
323
+ FileWriter setupCfgWriter = new FileWriter (setupCfg );
324
+ setupCfgWriter .write (setupCfgContent );
325
+ setupCfgWriter .close ();
326
+
327
+ Version actualCurrentVersion = Version .valueOf ("0.4.0" );
328
+ CurrentVersion currentVersion = new CurrentVersion ();
329
+ Version testCurrentVersion = currentVersion .getCurrentVersion (pyDir , "0.4.0" , mockedLogger );
330
+
331
+ assertThat (testCurrentVersion , is (notNullValue ()));
332
+ assertThat (testCurrentVersion , is (actualCurrentVersion ));
333
+ }
300
334
}
0 commit comments