Skip to content

Commit ef8b90b

Browse files
committed
JUnit 5 migration (part 2)
1 parent 374282f commit ef8b90b

File tree

26 files changed

+215
-308
lines changed

26 files changed

+215
-308
lines changed

changelog/org.eclipse.linuxtools.changelog.tests/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Bundle-Vendor: %Bundle-Vendor
77
Require-Bundle:
88
org.eclipse.jdt.core,
99
org.eclipse.jdt.ui,
10-
org.junit;bundle-version="4.8.1"
10+
junit-jupiter-api
1111
Fragment-Host: org.eclipse.linuxtools.changelog.core
1212
Bundle-RequiredExecutionEnvironment: JavaSE-21
1313
Bundle-ActivationPolicy: lazy

changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/core/formatters/tests/GNUFormatTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*******************************************************************************/
1010
package org.eclipse.linuxtools.changelog.core.formatters.tests;
1111

12-
import static org.junit.Assert.*;
1312

1413
import java.io.ByteArrayInputStream;
1514
import java.io.InputStream;
@@ -24,13 +23,16 @@
2423

2524
import static org.eclipse.linuxtools.changelog.tests.helpers.EditorHelper.closeEditor;
2625
import static org.eclipse.linuxtools.changelog.tests.helpers.EditorHelper.openEditor;
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.api.Assertions.assertNotNull;
28+
import static org.junit.jupiter.api.Assertions.assertNull;
2729
import static org.eclipse.linuxtools.changelog.tests.helpers.EditorHelper.getContent;
2830
import org.eclipse.ui.IEditorPart;
2931
import org.eclipse.ui.texteditor.AbstractTextEditor;
3032
import org.eclipse.ui.texteditor.IDocumentProvider;
31-
import org.junit.After;
32-
import org.junit.Before;
33-
import org.junit.Test;
33+
import org.junit.jupiter.api.AfterEach;
34+
import org.junit.jupiter.api.BeforeEach;
35+
import org.junit.jupiter.api.Test;
3436
import org.eclipse.jface.text.IDocument;
3537

3638
public class GNUFormatTest {
@@ -54,13 +56,13 @@ public class GNUFormatTest {
5456
private static final String FUNCTION_END_MARKER = ")";
5557
private static final String NEW_LINE = "\n";
5658

57-
@Before
59+
@BeforeEach
5860
public void setUp() throws Exception {
5961
gnuFormatter = new GNUFormat();
6062
project = new ChangeLogTestProject("GNUFormatterTest");
6163
}
6264

63-
@After
65+
@AfterEach
6466
public void tearDown() throws Exception {
6567
// Most tests in this class use changelogEditorPart. In order to avoid
6668
// spill-over from previous runs, truncate content (i.e. manually set

changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/core/tests/ChangeLogWriterTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
*******************************************************************************/
1010
package org.eclipse.linuxtools.changelog.core.tests;
1111

12-
import static org.junit.Assert.*;
12+
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
1314

1415
import java.io.BufferedReader;
1516
import java.io.ByteArrayInputStream;
@@ -22,9 +23,9 @@
2223
import org.eclipse.core.resources.IFile;
2324
import org.eclipse.core.runtime.CoreException;
2425
import org.eclipse.ui.IEditorPart;
25-
import org.junit.After;
26-
import org.junit.Before;
27-
import org.junit.Test;
26+
import org.junit.jupiter.api.AfterEach;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
2829
import org.eclipse.linuxtools.changelog.core.IFormatterChangeLogContrib;
2930
import org.eclipse.linuxtools.changelog.tests.fixtures.ChangeLogTestProject;
3031
import org.eclipse.linuxtools.changelog.tests.helpers.EditorHelper;
@@ -48,7 +49,7 @@ public class ChangeLogWriterTest {
4849
"\t* this/file/does/not/really/exist/SpringRoll.java: new file\n\n";
4950

5051

51-
@Before
52+
@BeforeEach
5253
public void setUp() throws Exception {
5354
clogWriter = new ChangeLogWriter();
5455
// create a testproject and add a file to it
@@ -63,7 +64,7 @@ public void setUp() throws Exception {
6364
newFileInputStream);
6465
}
6566

66-
@After
67+
@AfterEach
6768
public void tearDown() throws CoreException {
6869
// dispose testproject
6970
project.getTestProject().delete(true, null);

changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/parsers/tests/CParserTest.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
import static org.eclipse.linuxtools.changelog.tests.helpers.EditorHelper.closeEditor;
1313
import static org.eclipse.linuxtools.changelog.tests.helpers.EditorHelper.getContent;
1414
import static org.eclipse.linuxtools.changelog.tests.helpers.EditorHelper.openEditor;
15-
import static org.junit.Assert.assertEquals;
16-
import static org.junit.Assert.assertNotNull;
17-
import static org.junit.Assert.assertNull;
18-
import static org.junit.Assert.assertTrue;
15+
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
17+
import static org.junit.jupiter.api.Assertions.assertNotNull;
18+
import static org.junit.jupiter.api.Assertions.assertNull;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
1920

2021
import java.io.ByteArrayInputStream;
2122
import java.io.InputStream;
@@ -34,9 +35,9 @@
3435
import org.eclipse.ui.IStorageEditorInput;
3536
import org.eclipse.ui.texteditor.AbstractTextEditor;
3637
import org.eclipse.ui.texteditor.IDocumentProvider;
37-
import org.junit.After;
38-
import org.junit.Before;
39-
import org.junit.Test;
38+
import org.junit.jupiter.api.AfterEach;
39+
import org.junit.jupiter.api.BeforeEach;
40+
import org.junit.jupiter.api.Test;
4041

4142
/**
4243
* CParser test suite.
@@ -53,13 +54,13 @@ public class CParserTest {
5354
// The IEditorPart corresponding to the ChangeLog file
5455
private IEditorPart cppSourceEditorPart = null;
5556

56-
@Before
57+
@BeforeEach
5758
public void setUp() throws Exception {
5859
cParser = ChangeLogExtensionManager.getExtensionManager().getParserContributor("CEditor");
5960
project = new ChangeLogTestProject("c-parser-test-project");
6061
}
6162

62-
@After
63+
@AfterEach
6364
public void tearDown() throws Exception {
6465
// Tests in this class use javaSourceEditorPart. In order to avoid
6566
// spill-over from previous runs, truncate content (i.e. manually set
@@ -114,7 +115,7 @@ public void canParseCurrentFunctionFromCFile() throws Exception {
114115
assertEquals(cSourceCode, getContent(cppSourceEditorPart));
115116

116117
// make sure we have the proper editor type
117-
assertTrue( cppSourceEditorPart instanceof AbstractTextEditor );
118+
assertInstanceOf(AbstractTextEditor.class, cppSourceEditorPart );
118119

119120
// Select the snippet we want
120121
int selectionStart = cSourceCode.indexOf(OFFSET_MARKER);
@@ -166,7 +167,7 @@ public void canDetermineThatInNoFunctionInCFile() throws Exception {
166167
assertEquals(cSourceCode, getContent(cppSourceEditorPart));
167168

168169
// make sure we have the proper editor type
169-
assertTrue( cppSourceEditorPart instanceof AbstractTextEditor );
170+
assertInstanceOf(AbstractTextEditor.class , cppSourceEditorPart);
170171

171172
// Select the snippet we want
172173
int selectionStart = cSourceCode.indexOf(OFFSET_MARKER);
@@ -222,7 +223,7 @@ public void canParseCurrentlySelectedVariableIdentifierInCppFile() throws Except
222223
assertEquals(cppSourceCode, getContent(cppSourceEditorPart));
223224

224225
// make sure we have the proper editor type
225-
assertTrue( cppSourceEditorPart instanceof AbstractTextEditor );
226+
assertInstanceOf(AbstractTextEditor.class, cppSourceEditorPart);
226227

227228
// Select the snippet we want
228229
int selectionStart = cppSourceCode.indexOf(expectedIdentifier);
@@ -278,7 +279,7 @@ public void canParseClassNameIfNoVariableIdentifierSelectedInCppFile() throws Ex
278279
assertEquals(cppSourceCode, getContent(cppSourceEditorPart));
279280

280281
// make sure we have the proper editor type
281-
assertTrue( cppSourceEditorPart instanceof AbstractTextEditor );
282+
assertInstanceOf(AbstractTextEditor.class, cppSourceEditorPart);
282283

283284
// Select the snippet we want
284285
int selectionStart = cppSourceCode.indexOf(OFFSET_MARKER);
@@ -331,7 +332,7 @@ public void canParseCurrentMethodNameInCppFile() throws Exception {
331332
assertEquals(cppSourceCode, getContent(cppSourceEditorPart));
332333

333334
// make sure we have the proper editor type
334-
assertTrue( cppSourceEditorPart instanceof AbstractTextEditor );
335+
assertInstanceOf(AbstractTextEditor.class, cppSourceEditorPart);
335336

336337
// Select the snippet we want
337338
int selectionStart = cppSourceCode.indexOf(OFFSET_MARKER);
@@ -388,7 +389,7 @@ public void canParseCurrentFunctionInCppFile() throws Exception {
388389
assertEquals(cppSourceCode, getContent(cppSourceEditorPart));
389390

390391
// make sure we have the proper editor type
391-
assertTrue( cppSourceEditorPart instanceof AbstractTextEditor );
392+
assertInstanceOf(AbstractTextEditor.class, cppSourceEditorPart);
392393

393394
// Select the snippet we want
394395
int selectionStart = cppSourceCode.indexOf(OFFSET_MARKER);

changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/parsers/tests/JavaParserTest.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
import static org.eclipse.linuxtools.changelog.tests.helpers.EditorHelper.closeEditor;
1313
import static org.eclipse.linuxtools.changelog.tests.helpers.EditorHelper.getContent;
1414
import static org.eclipse.linuxtools.changelog.tests.helpers.EditorHelper.openEditor;
15-
import static org.junit.Assert.assertEquals;
16-
import static org.junit.Assert.assertNotNull;
17-
import static org.junit.Assert.assertNull;
18-
import static org.junit.Assert.assertTrue;
15+
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
17+
import static org.junit.jupiter.api.Assertions.assertNotNull;
18+
import static org.junit.jupiter.api.Assertions.assertNull;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
1920

2021
import java.io.ByteArrayInputStream;
2122
import java.io.InputStream;
@@ -31,9 +32,9 @@
3132
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
3233
import org.eclipse.ui.texteditor.AbstractTextEditor;
3334
import org.eclipse.ui.texteditor.IDocumentProvider;
34-
import org.junit.After;
35-
import org.junit.Before;
36-
import org.junit.Test;
35+
import org.junit.jupiter.api.AfterEach;
36+
import org.junit.jupiter.api.BeforeEach;
37+
import org.junit.jupiter.api.Test;
3738

3839
/**
3940
* JavaParser test suite.
@@ -50,15 +51,15 @@ public class JavaParserTest {
5051
// The IEditorPart corresponding to the ChangeLog file
5152
private IEditorPart javaSourceEditorPart = null;
5253

53-
@Before
54+
@BeforeEach
5455
public void setUp() throws Exception {
5556
javaParser = ChangeLogExtensionManager.getExtensionManager().getParserContributor("CompilationUnitEditor");
5657
project = new ChangeLogTestProject("java-parser-test-project");
5758
// make it a Java project
5859
project.addJavaNature();
5960
}
6061

61-
@After
62+
@AfterEach
6263
public void tearDown() throws Exception {
6364
// Tests in this class use javaSourceEditorPart. In order to avoid
6465
// spill-over from previous runs, truncate content (i.e. manually set
@@ -110,7 +111,7 @@ public void canParseCurrentMethod() throws Exception {
110111
assertEquals(javaSourceCode, getContent(javaSourceEditorPart));
111112

112113
// make sure we have the proper editor type
113-
assertTrue( javaSourceEditorPart instanceof AbstractDecoratedTextEditor );
114+
assertInstanceOf(AbstractDecoratedTextEditor.class, javaSourceEditorPart);
114115

115116
// Select the snippet we want
116117
int selectionStart = javaSourceCode.indexOf(OFFSET_MARKER);
@@ -160,7 +161,7 @@ public void canParseSelectedField() throws Exception {
160161
assertEquals(javaSourceCode, getContent(javaSourceEditorPart));
161162

162163
// make sure we have the proper editor type
163-
assertTrue( javaSourceEditorPart instanceof AbstractDecoratedTextEditor );
164+
assertInstanceOf(AbstractDecoratedTextEditor.class, javaSourceEditorPart);
164165

165166
// Select the snippet we want
166167
int selectionStart = javaSourceCode.indexOf(expectedFieldName);
@@ -214,7 +215,7 @@ public void canIdentifyStaticInitializerWhenInStaticInstanceInitializer() throws
214215
assertEquals(javaSourceCode, getContent(javaSourceEditorPart));
215216

216217
// make sure we have the proper editor type
217-
assertTrue( javaSourceEditorPart instanceof AbstractDecoratedTextEditor );
218+
assertInstanceOf(AbstractDecoratedTextEditor.class, javaSourceEditorPart);
218219

219220
// Select the snippet we want
220221
int selectionStart = javaSourceCode.indexOf(OFFSET_MARKER);
@@ -268,7 +269,7 @@ public void canIdentifyStaticInitializerWhenInStaticClassInitializer() throws Ex
268269
assertEquals(javaSourceCode, getContent(javaSourceEditorPart));
269270

270271
// make sure we have the proper editor type
271-
assertTrue( javaSourceEditorPart instanceof AbstractDecoratedTextEditor );
272+
assertInstanceOf(AbstractDecoratedTextEditor.class, javaSourceEditorPart);
272273

273274
// Select the snippet we want
274275
int selectionStart = javaSourceCode.indexOf(OFFSET_MARKER);
@@ -329,7 +330,7 @@ public void canIdentifyMethodWithinNestedClass() throws Exception {
329330
assertEquals(javaSourceCode, getContent(javaSourceEditorPart));
330331

331332
// make sure we have the proper editor type
332-
assertTrue( javaSourceEditorPart instanceof AbstractDecoratedTextEditor );
333+
assertInstanceOf(AbstractDecoratedTextEditor.class, javaSourceEditorPart);
333334

334335
// Select the snippet we want
335336
int selectionStart = javaSourceCode.indexOf(OFFSET_MARKER);
@@ -392,7 +393,7 @@ public void canIdentifyFieldWithinNestedClass() throws Exception {
392393
assertEquals(javaSourceCode, getContent(javaSourceEditorPart));
393394

394395
// make sure we have the proper editor type
395-
assertTrue( javaSourceEditorPart instanceof AbstractDecoratedTextEditor );
396+
assertInstanceOf(AbstractDecoratedTextEditor.class, javaSourceEditorPart);
396397

397398
// Select the snippet we want
398399
int selectionStart = javaSourceCode.indexOf(currentFieldName);
@@ -448,7 +449,7 @@ public void canDetermineThatSelectionIsJustInClass() throws Exception {
448449
assertEquals(javaSourceCode, getContent(javaSourceEditorPart));
449450

450451
// make sure we have the proper editor type
451-
assertTrue( javaSourceEditorPart instanceof AbstractDecoratedTextEditor );
452+
assertInstanceOf(AbstractDecoratedTextEditor.class, javaSourceEditorPart);
452453

453454
// Select the right point
454455
int selectionStart = javaSourceCode.indexOf(';') + 2;

changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/fixtures/TestChangeLogTestProject.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
*******************************************************************************/
1010
package org.eclipse.linuxtools.changelog.tests.fixtures;
1111

12-
import static org.junit.Assert.*;
12+
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertFalse;
15+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
16+
import static org.junit.jupiter.api.Assertions.assertNotNull;
17+
import static org.junit.jupiter.api.Assertions.assertThrows;
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
1319

1420
import java.io.BufferedReader;
1521
import java.io.ByteArrayInputStream;
@@ -22,21 +28,21 @@
2228
import org.eclipse.core.resources.IResource;
2329
import org.eclipse.core.runtime.Path;
2430
import org.eclipse.jdt.core.IJavaProject;
25-
import org.junit.After;
26-
import org.junit.Before;
27-
import org.junit.Test;
31+
import org.junit.jupiter.api.AfterEach;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Test;
2834
import org.eclipse.cdt.core.model.CoreModel;
2935

3036
public class TestChangeLogTestProject {
3137

3238
private ChangeLogTestProject project;
3339

34-
@Before
40+
@BeforeEach
3541
public void setUp() throws Exception {
3642
project = new ChangeLogTestProject("com.redhat.testchangelog.project");
3743
}
3844

39-
@After
45+
@AfterEach
4046
public void tearDown() throws Exception {
4147
// dispose
4248
project.getTestProject().delete(true, null);
@@ -77,7 +83,7 @@ public void testAddFileToProject() throws Exception {
7783
assertNotNull(createdFile);
7884
assertEquals("this/is/a/testpath/testfile.txt", createdFile.getProjectRelativePath().toString());
7985
assertEquals("testfile.txt", createdFile.getName());
80-
assertTrue(createdFile instanceof IFile);
86+
assertInstanceOf(IFile.class, createdFile);
8187

8288
// Content should be "some content"
8389
try (BufferedReader br = new BufferedReader(new InputStreamReader(
@@ -86,16 +92,8 @@ public void testAddFileToProject() throws Exception {
8692
assertEquals(fileContent, actualContent);
8793
}
8894

89-
// this should throw an IllegalStateException
90-
boolean exceptionTrown = false;
91-
try {
92-
project.addFileToProject("donnot/care", "not_important.java",
93-
null /* should cause exception */);
94-
} catch (IllegalStateException e) {
95-
// pass
96-
exceptionTrown = true;
97-
}
98-
assertTrue(exceptionTrown);
95+
assertThrows(IllegalStateException.class, () -> project.addFileToProject("donnot/care", "not_important.java",
96+
null /* should cause exception */));
9997
}
10098

10199
/**

gcov/org.eclipse.linuxtools.gcov.test/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Bundle-Name: %bundleName
44
Bundle-SymbolicName: org.eclipse.linuxtools.gcov.test
55
Bundle-Version: 4.1.1.qualifier
66
Bundle-Vendor: %bundleProvider
7-
Require-Bundle: org.junit;bundle-version="4.10.0",
7+
Require-Bundle: junit-jupiter-api,junit-platform-suite-api,
88
org.eclipse.linuxtools.gcov.launch;bundle-version="1.0.0",
99
org.eclipse.cdt.managedbuilder.gnu.ui;bundle-version="8.0.0",
1010
org.eclipse.linuxtools.profiling.tests,

gcov/org.eclipse.linuxtools.gcov.test/pom.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@
3030
<groupId>org.eclipse.tycho</groupId>
3131
<artifactId>tycho-surefire-plugin</artifactId>
3232
<configuration>
33-
<excludes>
34-
<!-- test mojo matches TestProject be default and treats it as PojoTest -->
35-
<exclude>**/Test*.class</exclude>
36-
</excludes>
3733
<testClass>org.eclipse.linuxtools.internal.gcov.test.AllGcovTests</testClass>
38-
<useUIHarness>true</useUIHarness>
34+
<useUIHarness>true</useUIHarness>
3935
<useUIThread>false</useUIThread>
4036
<dependencies>
4137
<dependency>

0 commit comments

Comments
 (0)