Skip to content

Commit c521fc2

Browse files
committed
Extract utilities from AbstractAntUITest into AntUITestUtil
In order to remove the inheritance hierarchy of Ant UI tests for JUnit 5 migration, this moves the utility methods embedded into the inheritance hierarchy via the AbstractAntUITest root class to the dedicated AntUITestUtil.
1 parent 56cd0a1 commit c521fc2

File tree

15 files changed

+221
-208
lines changed

15 files changed

+221
-208
lines changed

ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.ant.tests.ui.debug;
1515

16+
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getIFile;
1617
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration;
1718
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchManager;
1819
import static org.junit.Assert.assertNotNull;

ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/BreakpointTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.ant.tests.ui.debug;
1515

16+
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getIFile;
1617
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration;
1718
import static org.junit.Assert.assertEquals;
1819
import static org.junit.Assert.assertNotNull;

ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/StackTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.ant.tests.ui.debug;
1515

1616
import static org.assertj.core.api.Assertions.assertThat;
17+
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getIFile;
1718

1819
import org.eclipse.ant.internal.launching.debug.model.AntThread;
1920
import org.eclipse.core.resources.IFile;

ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/AntEditorTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*******************************************************************************/
1515
package org.eclipse.ant.tests.ui.editor;
1616

17+
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getIFile;
1718
import static org.junit.Assert.assertEquals;
1819
import static org.junit.Assert.assertNotNull;
1920
import static org.junit.Assert.assertTrue;

ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/CodeCompletionTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import static java.util.function.Function.identity;
2222
import static org.assertj.core.api.Assertions.assertThat;
23+
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getBuildFile;
24+
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getIFile;
2325
import static org.junit.Assert.assertEquals;
2426
import static org.junit.Assert.assertFalse;
2527
import static org.junit.Assert.assertNotNull;

ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/OccurrencesFinderTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.ant.tests.ui.editor;
1515

16+
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getIFile;
1617
import static org.junit.Assert.assertNotNull;
1718
import static org.junit.Assert.assertTrue;
1819

ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/XmlDocumentFormatterTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.ant.tests.ui.editor.formatter;
1515

16+
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getBuildFile;
17+
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getReaderContentAsString;
1618
import static org.junit.Assert.assertEquals;
1719

1820
import java.nio.file.Files;

ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,11 @@
1515
package org.eclipse.ant.tests.ui;
1616

1717
import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
18-
import org.eclipse.swt.widgets.Display;
19-
import org.eclipse.ui.console.IHyperlink;
2018
import org.junit.Rule;
2119

2220
public abstract class AbstractAntUIBuildTest extends AbstractAntUITest {
2321

2422
@Rule
2523
public RunInSeparateThreadRule runInSeparateThread = new RunInSeparateThreadRule();
2624

27-
protected void activateLink(final IHyperlink link) {
28-
Display.getDefault().asyncExec(() -> link.linkActivated());
29-
}
30-
3125
}

ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntUtilTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.eclipse.ant.tests.ui;
1616

1717
import static org.assertj.core.api.Assertions.assertThat;
18+
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getBuildFile;
1819
import static org.junit.Assert.assertEquals;
1920
import static org.junit.Assert.assertFalse;
2021
import static org.junit.Assert.assertNotNull;

ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntViewTests.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717
import static org.junit.Assert.assertFalse;
1818
import static org.junit.Assert.assertNotNull;
1919
import static org.junit.Assert.assertTrue;
20+
import static org.junit.Assert.fail;
2021

22+
import java.lang.reflect.InvocationTargetException;
2123
import java.lang.reflect.Method;
2224
import java.util.Collections;
2325

2426
import org.eclipse.ant.internal.ui.AntUtil;
2527
import org.eclipse.ant.internal.ui.preferences.FileFilter;
2628
import org.eclipse.ant.internal.ui.views.actions.AddBuildFilesAction;
2729
import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
30+
import org.eclipse.core.runtime.Assert;
2831
import org.eclipse.core.runtime.CoreException;
2932
import org.eclipse.jface.action.ActionContributionItem;
3033
import org.eclipse.jface.action.IContributionItem;
@@ -108,4 +111,54 @@ boolean canAccept(String extn) {
108111
}
109112
}
110113

114+
/**
115+
* This is to help in increasing the test coverage by enabling access to fields
116+
* and execution of methods irrespective of their Java language access
117+
* permissions.
118+
*
119+
* More accessor methods can be added to this on a need basis
120+
*/
121+
private static abstract class TypeProxy {
122+
123+
Object master = null;
124+
125+
protected TypeProxy(Object obj) {
126+
master = obj;
127+
}
128+
129+
/**
130+
* Gets the method with the given method name and argument types.
131+
*
132+
* @param methodName the method name
133+
* @param types the argument types
134+
* @return the method
135+
*/
136+
protected Method get(String methodName, Class<?>[] types) {
137+
Method method = null;
138+
try {
139+
method = master.getClass().getDeclaredMethod(methodName, types);
140+
} catch (SecurityException | NoSuchMethodException e) {
141+
fail();
142+
}
143+
Assert.isNotNull(method);
144+
method.setAccessible(true);
145+
return method;
146+
}
147+
148+
/**
149+
* Invokes the given method with the given arguments.
150+
*
151+
* @param method the given method
152+
* @param arguments the method arguments
153+
* @return the method return value
154+
*/
155+
protected Object invoke(Method method, Object[] arguments) {
156+
try {
157+
return method.invoke(master, arguments);
158+
} catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
159+
fail();
160+
}
161+
return null;
162+
}
163+
}
111164
}

0 commit comments

Comments
 (0)