Skip to content

Commit b95d0ec

Browse files
committed
Migrate resources propertytester tests to JUnit 5 #903
Migrates the tests in org.eclipse.core.tests.interal.propertytester to JUnit 5. - Exchange JUnit 4 test annotations - Replace JUnit 4 assertions with JUnit 5 assertions - Parameterize tests Contributes to #903
1 parent 1016b36 commit b95d0ec

File tree

1 file changed

+40
-55
lines changed

1 file changed

+40
-55
lines changed

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/propertytester/FilePropertyTesterTest.java

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,109 +16,94 @@
1616
import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
1717
import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream;
1818
import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor;
19-
import static org.junit.Assert.assertFalse;
20-
import static org.junit.Assert.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import java.io.ByteArrayInputStream;
2323
import java.nio.charset.StandardCharsets;
24+
import java.util.List;
25+
import java.util.stream.Stream;
2426
import org.eclipse.core.internal.propertytester.FilePropertyTester;
2527
import org.eclipse.core.resources.IFile;
2628
import org.eclipse.core.resources.IProject;
2729
import org.eclipse.core.runtime.CoreException;
28-
import org.eclipse.core.tests.resources.WorkspaceTestRule;
2930
import org.eclipse.core.tests.resources.content.IContentTypeManagerTest;
30-
import org.junit.Before;
31-
import org.junit.Rule;
32-
import org.junit.Test;
31+
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.extension.ExtendWith;
34+
import org.junit.jupiter.params.ParameterizedTest;
35+
import org.junit.jupiter.params.provider.MethodSource;
3336

37+
@ExtendWith(WorkspaceResetExtension.class)
3438
public class FilePropertyTesterTest {
3539

36-
@Rule
37-
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();
38-
3940
private static final String CONTENT_TYPE_ID = "contentTypeId";
4041
private static final String IS_KIND_OF = "kindOf";
4142
private static final String USE_FILENAME_ONLY = "useFilenameOnly";
4243

4344
private FilePropertyTester tester = null;
4445
private IProject project = null;
4546

46-
@Before
47+
@BeforeEach
4748
public void setUp() throws CoreException {
4849
project = getWorkspace().getRoot().getProject("project1");
4950
project.create(createTestMonitor());
5051
project.open(createTestMonitor());
5152
tester = new FilePropertyTester();
5253
}
5354

54-
@Test
55-
public void testNonExistingTextFile() throws Throwable {
55+
private static Stream<List<String>> arguments() {
56+
return Stream.of( //
57+
List.of(), //
58+
List.of(IS_KIND_OF), //
59+
List.of(USE_FILENAME_ONLY), //
60+
List.of(IS_KIND_OF, USE_FILENAME_ONLY) //
61+
);
62+
}
63+
64+
@ParameterizedTest
65+
@MethodSource("arguments")
66+
public void testNonExistingTextFile(List<String> arguments) throws Throwable {
5667
String expected = "org.eclipse.core.runtime.text";
5768
IFile target = project.getFile("tmp.txt");
5869

59-
boolean ret;
60-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {}, expected);
61-
assertFalse("1.0", ret);
62-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {IS_KIND_OF}, expected);
63-
assertFalse("1.1", ret);
64-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {USE_FILENAME_ONLY}, expected);
65-
assertTrue("1.2", ret);
66-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {IS_KIND_OF, USE_FILENAME_ONLY}, expected);
67-
assertTrue("1.3", ret);
68-
70+
boolean testResult = tester.test(target, CONTENT_TYPE_ID, arguments.toArray(), expected);
71+
assertEquals(arguments.contains(USE_FILENAME_ONLY), testResult);
6972
}
7073

71-
@Test
72-
public void testExistingTextFile() throws Throwable {
74+
@ParameterizedTest
75+
@MethodSource("arguments")
76+
public void testExistingTextFile(List<String> arguments) throws Throwable {
7377
String expected = "org.eclipse.core.runtime.text";
7478
IFile target = project.getFile("tmp.txt");
7579
target.create(createRandomContentsStream(), true, createTestMonitor());
7680

77-
boolean ret;
78-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {}, expected);
79-
assertTrue("1.0", ret);
80-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {IS_KIND_OF}, expected);
81-
assertTrue("1.1", ret);
82-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {USE_FILENAME_ONLY}, expected);
83-
assertTrue("1.2", ret);
84-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {IS_KIND_OF, USE_FILENAME_ONLY}, expected);
85-
assertTrue("1.3", ret);
81+
assertTrue(tester.test(target, CONTENT_TYPE_ID, arguments.toArray(), expected));
8682
}
8783

88-
@Test
89-
public void testNonExistingNsRootElementFile() throws Throwable {
84+
@ParameterizedTest
85+
@MethodSource("arguments")
86+
public void testNonExistingNsRootElementFile(List<String> arguments) throws Throwable {
9087
String expectedBase = "org.eclipse.core.runtime.xml";
9188
String expectedExact = "org.eclipse.core.tests.resources.ns-root-element";
89+
String expected = arguments.isEmpty() ? expectedExact : expectedBase;
9290
IFile target = project.getFile("tmp.xml");
9391

94-
boolean ret;
95-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {}, expectedExact);
96-
assertFalse("1.0", ret);
97-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {IS_KIND_OF}, expectedBase);
98-
assertFalse("1.1", ret);
99-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {USE_FILENAME_ONLY}, expectedBase);
100-
assertTrue("1.2", ret);
101-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {IS_KIND_OF, USE_FILENAME_ONLY}, expectedBase);
102-
assertTrue("1.3", ret);
92+
boolean testResult = tester.test(target, CONTENT_TYPE_ID, arguments.toArray(), expected);
93+
assertEquals(arguments.contains(USE_FILENAME_ONLY), testResult);
10394
}
10495

105-
@Test
106-
public void testExistingNsRootElementFile() throws Throwable {
96+
@ParameterizedTest
97+
@MethodSource("arguments")
98+
public void testExistingNsRootElementFile(List<String> arguments) throws Throwable {
10799
String expectedBase = "org.eclipse.core.runtime.xml";
108100
String expectedExact = "org.eclipse.core.tests.resources.ns-root-element";
101+
String expected = arguments.isEmpty() ? expectedExact : expectedBase;
109102
IFile target = project.getFile("tmp.xml");
110103
byte[] bytes = IContentTypeManagerTest.XML_ROOT_ELEMENT_NS_MATCH1.getBytes(StandardCharsets.UTF_8);
111104
target.create(new ByteArrayInputStream(bytes), true, createTestMonitor());
112105

113-
boolean ret;
114-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {}, expectedExact);
115-
assertTrue("1.0", ret);
116-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {IS_KIND_OF}, expectedBase);
117-
assertTrue("1.1", ret);
118-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {USE_FILENAME_ONLY}, expectedBase);
119-
assertTrue("1.2", ret);
120-
ret = tester.test(target, CONTENT_TYPE_ID, new String[] {IS_KIND_OF, USE_FILENAME_ONLY}, expectedBase);
121-
assertTrue("1.3", ret);
106+
assertTrue(tester.test(target, CONTENT_TYPE_ID, arguments.toArray(), expected));
122107
}
123108

124109
}

0 commit comments

Comments
 (0)