|
16 | 16 | import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
|
17 | 17 | import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream;
|
18 | 18 | 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; |
21 | 21 |
|
22 | 22 | import java.io.ByteArrayInputStream;
|
23 | 23 | import java.nio.charset.StandardCharsets;
|
| 24 | +import java.util.List; |
| 25 | +import java.util.stream.Stream; |
24 | 26 | import org.eclipse.core.internal.propertytester.FilePropertyTester;
|
25 | 27 | import org.eclipse.core.resources.IFile;
|
26 | 28 | import org.eclipse.core.resources.IProject;
|
27 | 29 | import org.eclipse.core.runtime.CoreException;
|
28 |
| -import org.eclipse.core.tests.resources.WorkspaceTestRule; |
29 | 30 | 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; |
33 | 36 |
|
| 37 | +@ExtendWith(WorkspaceResetExtension.class) |
34 | 38 | public class FilePropertyTesterTest {
|
35 | 39 |
|
36 |
| - @Rule |
37 |
| - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); |
38 |
| - |
39 | 40 | private static final String CONTENT_TYPE_ID = "contentTypeId";
|
40 | 41 | private static final String IS_KIND_OF = "kindOf";
|
41 | 42 | private static final String USE_FILENAME_ONLY = "useFilenameOnly";
|
42 | 43 |
|
43 | 44 | private FilePropertyTester tester = null;
|
44 | 45 | private IProject project = null;
|
45 | 46 |
|
46 |
| - @Before |
| 47 | + @BeforeEach |
47 | 48 | public void setUp() throws CoreException {
|
48 | 49 | project = getWorkspace().getRoot().getProject("project1");
|
49 | 50 | project.create(createTestMonitor());
|
50 | 51 | project.open(createTestMonitor());
|
51 | 52 | tester = new FilePropertyTester();
|
52 | 53 | }
|
53 | 54 |
|
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 { |
56 | 67 | String expected = "org.eclipse.core.runtime.text";
|
57 | 68 | IFile target = project.getFile("tmp.txt");
|
58 | 69 |
|
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); |
69 | 72 | }
|
70 | 73 |
|
71 |
| - @Test |
72 |
| - public void testExistingTextFile() throws Throwable { |
| 74 | + @ParameterizedTest |
| 75 | + @MethodSource("arguments") |
| 76 | + public void testExistingTextFile(List<String> arguments) throws Throwable { |
73 | 77 | String expected = "org.eclipse.core.runtime.text";
|
74 | 78 | IFile target = project.getFile("tmp.txt");
|
75 | 79 | target.create(createRandomContentsStream(), true, createTestMonitor());
|
76 | 80 |
|
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)); |
86 | 82 | }
|
87 | 83 |
|
88 |
| - @Test |
89 |
| - public void testNonExistingNsRootElementFile() throws Throwable { |
| 84 | + @ParameterizedTest |
| 85 | + @MethodSource("arguments") |
| 86 | + public void testNonExistingNsRootElementFile(List<String> arguments) throws Throwable { |
90 | 87 | String expectedBase = "org.eclipse.core.runtime.xml";
|
91 | 88 | String expectedExact = "org.eclipse.core.tests.resources.ns-root-element";
|
| 89 | + String expected = arguments.isEmpty() ? expectedExact : expectedBase; |
92 | 90 | IFile target = project.getFile("tmp.xml");
|
93 | 91 |
|
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); |
103 | 94 | }
|
104 | 95 |
|
105 |
| - @Test |
106 |
| - public void testExistingNsRootElementFile() throws Throwable { |
| 96 | + @ParameterizedTest |
| 97 | + @MethodSource("arguments") |
| 98 | + public void testExistingNsRootElementFile(List<String> arguments) throws Throwable { |
107 | 99 | String expectedBase = "org.eclipse.core.runtime.xml";
|
108 | 100 | String expectedExact = "org.eclipse.core.tests.resources.ns-root-element";
|
| 101 | + String expected = arguments.isEmpty() ? expectedExact : expectedBase; |
109 | 102 | IFile target = project.getFile("tmp.xml");
|
110 | 103 | byte[] bytes = IContentTypeManagerTest.XML_ROOT_ELEMENT_NS_MATCH1.getBytes(StandardCharsets.UTF_8);
|
111 | 104 | target.create(new ByteArrayInputStream(bytes), true, createTestMonitor());
|
112 | 105 |
|
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)); |
122 | 107 | }
|
123 | 108 |
|
124 | 109 | }
|
0 commit comments