Skip to content

Commit d77f1f4

Browse files
Start tests migration to JUnit 5
- first step - easy cases
1 parent e59642b commit d77f1f4

File tree

15 files changed

+163
-145
lines changed

15 files changed

+163
-145
lines changed

maven-scm-api/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
<version>3.19.0</version>
4747
</dependency>
4848
<dependency>
49-
<groupId>junit</groupId>
50-
<artifactId>junit</artifactId>
49+
<groupId>org.junit.jupiter</groupId>
50+
<artifactId>junit-jupiter-api</artifactId>
5151
<scope>test</scope>
5252
</dependency>
5353
<dependency>

maven-scm-api/src/test/java/org/apache/maven/scm/ChangeFileTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,33 @@
1818
*/
1919
package org.apache.maven.scm;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

23-
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assert.assertNull;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertNull;
2525

2626
/**
2727
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse </a>
2828
*/
29-
public class ChangeFileTest {
29+
class ChangeFileTest {
3030
@Test
31-
public void testNewFile() {
31+
void testNewFile() {
3232
ChangeFile f = new ChangeFile("test.java");
3333
assertEquals("test.java", f.getName());
3434
assertNull(f.getRevision());
3535
assertEquals("test.java", f.toString());
3636
}
3737

3838
@Test
39-
public void testNewFileRevision() {
39+
void testNewFileRevision() {
4040
ChangeFile f = new ChangeFile("test.java", "1.2.3");
4141
assertEquals("test.java", f.getName());
4242
assertEquals("1.2.3", f.getRevision());
4343
assertEquals("test.java, 1.2.3", f.toString());
4444
}
4545

4646
@Test
47-
public void testNewRevisionFile() {
47+
void testNewRevisionFile() {
4848
ChangeFile f = new ChangeFile("test.java", "revision1");
4949
assertEquals("test.java", f.getName());
5050
assertEquals("revision1", f.getRevision());

maven-scm-api/src/test/java/org/apache/maven/scm/ChangeSetTest.java

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@
2222
import java.util.Calendar;
2323
import java.util.Date;
2424

25-
import org.junit.Before;
26-
import org.junit.Test;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2727

28-
import static org.junit.Assert.assertEquals;
29-
import static org.junit.Assert.assertFalse;
30-
import static org.junit.Assert.assertNotEquals;
31-
import static org.junit.Assert.assertNotNull;
32-
import static org.junit.Assert.assertTrue;
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertFalse;
30+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
31+
import static org.junit.jupiter.api.Assertions.assertNotNull;
32+
import static org.junit.jupiter.api.Assertions.assertTrue;
3333

3434
/**
3535
* Tests for the {@link ChangeSet}class
3636
*
3737
* @author dion
3838
*
3939
*/
40-
public class ChangeSetTest {
40+
class ChangeSetTest {
4141
/**
4242
* the {@link ChangeSet} used for testing
4343
*/
@@ -46,8 +46,8 @@ public class ChangeSetTest {
4646
/**
4747
* Initialize per test data
4848
*/
49-
@Before
50-
public void setUp() {
49+
@BeforeEach
50+
void setUp() {
5151
instance = createInstance();
5252
}
5353

@@ -64,10 +64,10 @@ private static ChangeSet createInstance() {
6464
* Test of addFile methods: using ChangeFile
6565
*/
6666
@Test
67-
public void testAddFileWithFile() {
67+
void testAddFileWithFile() {
6868
ChangeFile file = new ChangeFile("maven:dummy");
6969
instance.addFile(file);
70-
assertTrue("File name not found in list", instance.toString().indexOf("maven:dummy") != -1);
70+
assertTrue(instance.toString().indexOf("maven:dummy") != -1, "File name not found in list");
7171

7272
assertTrue(instance.containsFilename("maven:"));
7373
assertTrue(instance.containsFilename(":dummy"));
@@ -80,93 +80,93 @@ public void testAddFileWithFile() {
8080
* Test of toString method
8181
*/
8282
@Test
83-
public void testToString() {
83+
void testToString() {
8484
// dion, Mon Apr 01 00:00:00 EST 2002, comment
8585
String value = instance.toString();
86-
assertTrue("author not found in string", value.indexOf("dion") != -1);
87-
assertTrue("comment not found in string", value.indexOf("comment") != -1);
88-
assertTrue("date not found in string", value.indexOf("Mon Apr 01") != -1);
86+
assertTrue(value.indexOf("dion") != -1, "author not found in string");
87+
assertTrue(value.indexOf("comment") != -1, "comment not found in string");
88+
assertTrue(value.indexOf("Mon Apr 01") != -1, "date not found in string");
8989
}
9090

9191
/**
9292
* Test of getAuthor method
9393
*/
9494
@Test
95-
public void testGetAuthor() {
96-
assertEquals("Author value not retrieved correctly", "dion", instance.getAuthor());
95+
void testGetAuthor() {
96+
assertEquals("dion", instance.getAuthor(), "Author value not retrieved correctly");
9797
}
9898

9999
/**
100100
* Test of setAuthor method
101101
*/
102102
@Test
103-
public void testSetAuthor() {
103+
void testSetAuthor() {
104104
instance.setAuthor("maven:dion");
105-
assertEquals("Author not set correctly", "maven:dion", instance.getAuthor());
105+
assertEquals("maven:dion", instance.getAuthor(), "Author not set correctly");
106106
}
107107

108108
/**
109109
* Test of getComment method
110110
*/
111111
@Test
112-
public void testGetComment() {
113-
assertEquals("Comment value not retrieved correctly", "comment", instance.getComment());
112+
void testGetComment() {
113+
assertEquals("comment", instance.getComment(), "Comment value not retrieved correctly");
114114
}
115115

116116
/**
117117
* Test of setComment method
118118
*/
119119
@Test
120-
public void testSetComment() {
120+
void testSetComment() {
121121
instance.setComment("maven:comment");
122-
assertEquals("Comment not set correctly", "maven:comment", instance.getComment());
122+
assertEquals("maven:comment", instance.getComment(), "Comment not set correctly");
123123
}
124124

125125
/**
126126
* Test of getDate method
127127
*/
128128
@Test
129-
public void testGetDate() {
130-
assertEquals("Date value not retrieved correctly", getDate(2002, 3, 1), instance.getDate());
129+
void testGetDate() {
130+
assertEquals(getDate(2002, 3, 1), instance.getDate(), "Date value not retrieved correctly");
131131
}
132132

133133
/**
134134
* Test of setDate method with Date object
135135
*/
136136
@Test
137-
public void testSetDate() {
137+
void testSetDate() {
138138
Calendar cal = Calendar.getInstance();
139139
Date date = cal.getTime();
140140
instance.setDate(date);
141-
assertEquals("Date value not set correctly", date, instance.getDate());
141+
assertEquals(date, instance.getDate(), "Date value not set correctly");
142142
}
143143

144144
/**
145145
* Test of setDate method with String
146146
*/
147147
@Test
148-
public void testSetDateFromString() {
148+
void testSetDateFromString() {
149149
instance.setDate("2002/03/04 00:00:00");
150-
assertEquals("Date value not set correctly from a string", getDate(2002, 2, 4), instance.getDate());
150+
assertEquals(getDate(2002, 2, 4), instance.getDate(), "Date value not set correctly from a string");
151151
}
152152

153153
/**
154154
* Test of getDateFormatted method
155155
*/
156156
@Test
157-
public void testGetDateFormatted() {
158-
assertEquals("Date not formatted correctly", "2002-04-01", instance.getDateFormatted());
157+
void testGetDateFormatted() {
158+
assertEquals("2002-04-01", instance.getDateFormatted(), "Date not formatted correctly");
159159
}
160160

161161
/**
162162
* Test of getDateFormatted method
163163
*/
164164
@Test
165-
public void testGetTimeFormatted() {
166-
assertEquals("Time not formatted correctly", "00:00:00", instance.getTimeFormatted());
165+
void testGetTimeFormatted() {
166+
assertEquals("00:00:00", instance.getTimeFormatted(), "Time not formatted correctly");
167167
}
168168

169-
public static Date getDate(int year, int month, int day) {
169+
static Date getDate(int year, int month, int day) {
170170
Calendar cal = Calendar.getInstance();
171171

172172
cal.set(year, month, day, 0, 0, 0);
@@ -176,7 +176,7 @@ public static Date getDate(int year, int month, int day) {
176176
}
177177

178178
@Test
179-
public void testEscapeValue() {
179+
void testEscapeValue() {
180180
assertEquals("", ChangeSet.escapeValue(""));
181181
assertEquals("&apos;", ChangeSet.escapeValue("'"));
182182
assertEquals("a", ChangeSet.escapeValue("a"));
@@ -188,7 +188,7 @@ public void testEscapeValue() {
188188
}
189189

190190
@Test
191-
public void testEquals() {
191+
void testEquals() {
192192
ChangeSet instance2 = createInstance();
193193
assertEquals(instance, instance2);
194194

@@ -200,7 +200,7 @@ public void testEquals() {
200200
}
201201

202202
@Test
203-
public void testHashCode() {
203+
void testHashCode() {
204204
int hashCode1 = instance.hashCode();
205205
instance.setAuthor("anotherAuthor");
206206

@@ -210,7 +210,7 @@ public void testHashCode() {
210210
}
211211

212212
@Test
213-
public void testToXml() {
213+
void testToXml() {
214214
String sXml = instance.toXML();
215215
assertNotNull(sXml);
216216

@@ -219,7 +219,7 @@ public void testToXml() {
219219
}
220220

221221
@Test
222-
public void testToXmlWithFiles() {
222+
void testToXmlWithFiles() {
223223
instance.addFile(new ChangeFile("maven1:dummy"));
224224
instance.addFile(new ChangeFile("maven2:dummy2"));
225225

maven-scm-api/src/test/java/org/apache/maven/scm/ScmFileSetTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323
import java.util.Iterator;
2424
import java.util.List;
2525

26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727

28-
import static org.junit.Assert.assertEquals;
29-
import static org.junit.Assert.assertTrue;
30-
import static org.junit.Assert.fail;
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertTrue;
30+
import static org.junit.jupiter.api.Assertions.fail;
3131

3232
/**
3333
* @author dtran
3434
*/
35-
public class ScmFileSetTest {
35+
class ScmFileSetTest {
3636
private static String basedirPath;
3737

38-
public static String getBasedir() {
38+
private static String getBasedir() {
3939
if (basedirPath != null) {
4040
return basedirPath;
4141
}
@@ -54,25 +54,25 @@ private String removeBasedir(String filename) {
5454
}
5555

5656
@Test
57-
public void testFilesList() throws IOException {
57+
void testFilesList() throws IOException {
5858
ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/**");
5959
assertEquals("src", fileSet.getBasedir().getName());
6060
assertEquals("**/**", fileSet.getIncludes());
6161
// assertEquals( ScmFileSet.DEFAULT_EXCLUDES, fileSet.getExcludes() );
6262
assertTrue(
63+
fileSet.getFileList().size() > 10,
6364
"List of files should be longer than 10 elements, but received: "
64-
+ fileSet.getFileList().size(),
65-
fileSet.getFileList().size() > 10);
65+
+ fileSet.getFileList().size());
6666
}
6767

6868
@Test
69-
public void testFilesListWithoutIncludesResultsEmptyList() throws IOException {
69+
void testFilesListWithoutIncludesResultsEmptyList() {
7070
ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"));
7171
assertEquals(0, fileSet.getFileList().size());
7272
}
7373

7474
@Test
75-
public void testFilesListExcludes() throws IOException {
75+
void testFilesListExcludes() throws IOException {
7676
ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/**", "**/exclude/**");
7777

7878
List<File> files = fileSet.getFileList();
@@ -87,14 +87,14 @@ public void testFilesListExcludes() throws IOException {
8787
}
8888

8989
@Test
90-
public void testFilesListExcludes2() throws IOException {
90+
void testFilesListExcludes2() throws IOException {
9191
ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/scmfileset/**", "**/exclude/**");
9292

9393
assertEquals(2, fileSet.getFileList().size());
9494
}
9595

9696
@Test
97-
public void testFilesListNoExcludes() throws IOException {
97+
void testFilesListNoExcludes() throws IOException {
9898
ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/scmfileset/**");
9999

100100
assertEquals(4, fileSet.getFileList().size());

maven-scm-api/src/test/java/org/apache/maven/scm/ScmResultTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
*/
1919
package org.apache.maven.scm;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

23-
import static org.junit.Assert.assertNotSame;
24-
import static org.junit.Assert.assertTrue;
23+
import static org.junit.jupiter.api.Assertions.assertNotSame;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
2525

26-
public class ScmResultTest {
26+
class ScmResultTest {
2727

2828
private static final String PASSWORD = "secr$t";
2929

@@ -36,13 +36,13 @@ public class ScmResultTest {
3636
+ System.lineSeparator() + "fatal: Authentication failed for '" + SCM_URL_GIT_COLON + "'";
3737

3838
@Test
39-
public void testPasswordsAreMaskedInOutput() throws Exception {
39+
void testPasswordsAreMaskedInOutput() throws Exception {
4040
ScmResult result = new ScmResult("git push", "git-push failed", MOCK_ERROR_OUTPUT, false);
41-
assertNotSame("Command output contains password", MOCK_ERROR_OUTPUT, result.getCommandOutput());
42-
assertTrue("Command output not masked", result.getCommandOutput().contains(ScmResult.PASSWORD_PLACE_HOLDER));
41+
assertNotSame(MOCK_ERROR_OUTPUT, result.getCommandOutput(), "Command output contains password");
42+
assertTrue(result.getCommandOutput().contains(ScmResult.PASSWORD_PLACE_HOLDER), "Command output not masked");
4343

4444
result = new ScmResult("git push", "git-push failed", MOCK_ERROR_MULTILINE_OUTPUT, false);
45-
assertNotSame("Command output contains password", MOCK_ERROR_MULTILINE_OUTPUT, result.getCommandOutput());
46-
assertTrue("Command output not masked", result.getCommandOutput().contains(ScmResult.PASSWORD_PLACE_HOLDER));
45+
assertNotSame(MOCK_ERROR_MULTILINE_OUTPUT, result.getCommandOutput(), "Command output contains password");
46+
assertTrue(result.getCommandOutput().contains(ScmResult.PASSWORD_PLACE_HOLDER), "Command output not masked");
4747
}
4848
}

0 commit comments

Comments
 (0)