Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2006-10-31 18:51:16 +0000
committeratikhomirov2006-10-31 18:51:16 +0000
commit845ea0d4c1dedc9a5661a422e802404093d2661c (patch)
treee60bc621abf79c9edefaf65f4c8bb513ebaa62cf
parent22e2894c2ea5f1a3948845bd9449a0d0c3b03ab9 (diff)
downloadorg.eclipse.gmf-tooling-845ea0d4c1dedc9a5661a422e802404093d2661c.tar.gz
org.eclipse.gmf-tooling-845ea0d4c1dedc9a5661a422e802404093d2661c.tar.xz
org.eclipse.gmf-tooling-845ea0d4c1dedc9a5661a422e802404093d2661c.zip
FigureCheck refactored into chain
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java32
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java13
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/LabelSupportTest.java15
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/StandaloneMapModeTest.java23
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/StandalonePluginConverterTest.java5
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/FigureCheck.java66
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/FigureGeneratorUtil.java8
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/GenericFigureCheck.java2
8 files changed, 74 insertions, 90 deletions
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java
index c6690deb3..70f84fce7 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java
@@ -49,7 +49,7 @@ public class FigureCodegenTest extends FigureCodegenTestBase {
public void testGenPolylineConnection() {
performTests(getSessionSetup().getEcoreContainmentRef(), new FigureCheck() {
- public void checkFigure(IFigure figure) {
+ protected void checkFigure(IFigure figure) {
assertTrue(figure instanceof PolylineConnectionEx);
}
});
@@ -69,28 +69,28 @@ public class FigureCodegenTest extends FigureCodegenTestBase {
public void testGenCustomFigureWithAttributes(){
FigureCheck defaultCheckWithoutChildren = new GenericFigureCheck(getSessionSetup().getResult2()){
- protected void checkFigureChildren(Figure gmfFigure, IFigure d2dFigure) {
- //ScrollBar creates additional children that are missed in the model
- //Thus nothing to check here
- }
- };
- FigureCheck customCheck = new FigureCheck(){
- public void checkFigure(IFigure figure) {
+ protected void checkFigure(IFigure figure) {
assertTrue(figure instanceof ScrollBar);
ScrollBar custom = (ScrollBar)figure;
assertEquals(1, custom.getMinimum());
assertEquals(99, custom.getMaximum());
assertTrue(custom.isHorizontal());
-
assertEquals(new org.eclipse.draw2d.geometry.Dimension(100, 100), custom.getPreferredSize());
+
+ super.checkFigure(figure);
}
- };
- performTests(getSessionSetup().getResult2(), FigureCheck.combineChecks(customCheck, defaultCheckWithoutChildren));
+
+ protected void checkFigureChildren(Figure gmfFigure, IFigure d2dFigure) {
+ //ScrollBar creates additional children that are missed in the model
+ //Thus nothing to check here
+ }
+ };
+ performTests(getSessionSetup().getResult2(), defaultCheckWithoutChildren);
}
public void testGenCustomDecoration(){
FigureCheck customCheck = new FigureCheck(){
- public void checkFigure(IFigure figure) {
+ protected void checkFigure(IFigure figure) {
assertTrue(figure instanceof PolygonDecoration);
PolygonDecoration decoration = (PolygonDecoration)figure;
//we can not check scale directly, but following line checks it implicitly
@@ -98,7 +98,7 @@ public class FigureCodegenTest extends FigureCodegenTestBase {
}
};
- performTests(getSessionSetup().getResult1(), FigureCheck.combineChecks(customCheck, new GenericFigureCheck(getSessionSetup().getResult1())));
+ performTests(getSessionSetup().getResult1(), customCheck.chain(new GenericFigureCheck(getSessionSetup().getResult1())));
}
public void testGenCustomConnection(){
@@ -126,14 +126,14 @@ public class FigureCodegenTest extends FigureCodegenTestBase {
public void testFigureWithTwoBorderedChildren(){
FigureCheck staticFieldsCheck = new StaticFieldsChecker(1, Color.class);
- performTests(getSessionSetup().getRoot1(), FigureCheck.combineChecks(new GenericFigureCheck(getSessionSetup().getRoot1()), staticFieldsCheck));
+ performTests(getSessionSetup().getRoot1(), new GenericFigureCheck(getSessionSetup().getRoot1()).chain(staticFieldsCheck));
}
public void testFigureWithStaticFieldsForColorAndFonts(){
FigureCheck fontFieldsCheck = new StaticFieldsChecker(4, Font.class); //root + 3 labels
FigureCheck colorFieldsCheck = new StaticFieldsChecker(2, Color.class); // only RGB colors should get field
- performTests(getSessionSetup().getRoot(), FigureCheck.combineChecks(fontFieldsCheck, colorFieldsCheck));
+ performTests(getSessionSetup().getRoot(), fontFieldsCheck.chain(colorFieldsCheck));
}
public void testConnectionWithColor(){
@@ -150,7 +150,7 @@ public class FigureCodegenTest extends FigureCodegenTestBase {
myFieldClazz = fieldClazz;
}
- public void checkFigure(IFigure figure) {
+ protected void checkFigure(IFigure figure) {
Class figureClazz = figure.getClass();
Field[] fields = figureClazz.getDeclaredFields();
int staticFinalFields = 0;
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java
index 2b6216cd6..27fd0233a 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java
@@ -28,6 +28,10 @@ public class FigureCodegenTestBase extends TestCase implements NeedsSetup {
protected AbstractFigureGeneratorSetup mySessionSetup;
+ public FigureCodegenTestBase(String name) {
+ super(name);
+ }
+
public void configure(AbstractFigureGeneratorSetup sessionSetup) {
mySessionSetup = sessionSetup;
}
@@ -39,13 +43,6 @@ public class FigureCodegenTestBase extends TestCase implements NeedsSetup {
protected void performTests(Figure f, FigureCheck check) {
FigureGeneratorUtil.generateAndParse(f);
Class figureClass = mySessionSetup.getFigureClass(f);
- IFigure figure = check.instantiateFigure(figureClass);
- assertNotNull(figure);
- check.checkFigure(figure);
+ check.go(figureClass);
}
-
- public FigureCodegenTestBase(String name) {
- super(name);
- }
-
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/LabelSupportTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/LabelSupportTest.java
index ca45a63c6..4270313e0 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/LabelSupportTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/LabelSupportTest.java
@@ -47,34 +47,31 @@ public class LabelSupportTest extends FigureCodegenTestBase {
}
public void testDeepLabelGraphdefOnly(){
- performTests(getSessionSetup().getRoot(), FigureCheck.combineChecks(new GenericFigureCheck(getSessionSetup().getRoot()), new LabelAccessorCheck(getSessionSetup().getLabelName())));
+ performTests(getSessionSetup().getRoot());
}
protected void performTests(Figure figure) {
- performTests(figure, FigureCheck.combineChecks(new GenericFigureCheck(figure), new LabelAccessorCheck(getSessionSetup().getLabelName())));
+ performTests(figure, new GenericFigureCheck(figure).chain(new LabelAccessorCheck(getSessionSetup().getLabelName())));
}
private static class LabelAccessorCheck extends FigureCheck {
private final String myLabelName;
- private static final Class[] NO_PARAMS = new Class[0];
public LabelAccessorCheck(String labelName){
myLabelName = labelName;
}
- public void checkFigure(IFigure figure) {
+ protected void checkFigure(IFigure figure) {
assertNotNull(figure);
assertTrue("NodeEditPart requires this method in the inner figure class",
- hasMethod(figure, "getFigure" + CodeGenUtil.capName(myLabelName), NO_PARAMS));
+ hasMethod(figure, "getFigure" + CodeGenUtil.capName(myLabelName), null));
}
- private boolean hasMethod(Object instance, String methodName, Class[] params) {
+ private static boolean hasMethod(Object instance, String methodName, Class[] params) {
try {
Method method = instance.getClass().getMethod(methodName, params);
return method != null;
- } catch (SecurityException e) {
- return false;
- } catch (NoSuchMethodException e) {
+ } catch (Exception e) {
return false;
}
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/StandaloneMapModeTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/StandaloneMapModeTest.java
index 33ec4e569..778c4c4d3 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/StandaloneMapModeTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/StandaloneMapModeTest.java
@@ -12,7 +12,6 @@
package org.eclipse.gmf.tests.gen;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import junit.framework.TestCase;
@@ -22,7 +21,6 @@ import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.gmf.gmfgraph.Figure;
import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
-import org.eclipse.gmf.gmfgraph.Point;
import org.eclipse.gmf.gmfgraph.Rectangle;
import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator;
import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator.Config;
@@ -38,10 +36,6 @@ public class StandaloneMapModeTest extends TestCase {
super(name);
}
- protected void setUp() throws Exception {
- super.setUp();
- }
-
public void testStaticIdentityMapMode(){
Config config = FigureGeneratorUtil.createStandaloneGeneratorConfig(FigureGeneratorUtil.DEFAULT_FIGURE_PACKAGE, false);
FigureGeneratorUtil.performTests(createTestFigure(), new FigureSizeCheck(123, 456), config);
@@ -60,10 +54,7 @@ public class StandaloneMapModeTest extends TestCase {
private Figure createTestFigure(){
Rectangle result = GMFGraphFactory.eINSTANCE.createRectangle();
result.setName("TestFigure");
- Point size = GMFGraphFactory.eINSTANCE.createPoint();
- size.setX(123);
- size.setY(456);
- result.setSize(size);
+ result.setSize(FigureGeneratorUtil.createPoint(123, 456));
return result;
}
@@ -71,14 +62,10 @@ public class StandaloneMapModeTest extends TestCase {
private final Dimension mySize;
public FigureSizeCheck(int width, int height){
- this(new Dimension(width, height));
+ mySize = new Dimension(width, height);
}
- public FigureSizeCheck(Dimension size){
- mySize = size;
- }
-
- public void checkFigure(IFigure figure) {
+ protected void checkFigure(IFigure figure) {
assertEquals(mySize, figure.getSize());
}
}
@@ -93,7 +80,7 @@ public class StandaloneMapModeTest extends TestCase {
myConfig = config;
}
- public IFigure instantiateFigure(Class figureClass) {
+ protected IFigure instantiateFigure(Class figureClass) {
try {
hookMapMode();
} catch (Exception e) {
@@ -102,7 +89,7 @@ public class StandaloneMapModeTest extends TestCase {
return super.instantiateFigure(figureClass);
}
- private void hookMapMode() throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException{
+ private void hookMapMode() throws Exception {
Bundle bundle = Platform.getBundle(myConfig.getPluginID());
assertNotNull(bundle);
Class activatorClass = bundle.loadClass(myConfig.getPluginActivatorPackageName() + "." + myConfig.getPluginActivatorClassName());
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/StandalonePluginConverterTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/StandalonePluginConverterTest.java
index d9f213cb7..c1f55e52d 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/StandalonePluginConverterTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/StandalonePluginConverterTest.java
@@ -80,7 +80,7 @@ public class StandalonePluginConverterTest extends TestCase {
for (int i = 0; i < genResults.length; i++){
GeneratedClassData next = genResults[i];
- assertNotNull(FigureCheck.CHECK_CAN_CREATE_INSTANCE.instantiateFigure(next.getLoadedClass()));
+ FigureCheck.CHECK_CAN_CREATE_INSTANCE.go(next.getLoadedClass());
}
}
@@ -127,8 +127,7 @@ public class StandalonePluginConverterTest extends TestCase {
Class nextClass = searchForFigureName(mirroredClasses, nextOriginal.getName());
assertNotNull("Missed class for : " + nextOriginal.getName(), nextClass);
- FigureCheck nextCheck = new GenericFigureCheck(nextOriginal);
- nextCheck.checkFigure(nextCheck.instantiateFigure(nextClass));
+ new GenericFigureCheck(nextOriginal).go(nextClass);
}
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/FigureCheck.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/FigureCheck.java
index 49844a9d7..61ce89d59 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/FigureCheck.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/FigureCheck.java
@@ -14,53 +14,61 @@ package org.eclipse.gmf.tests.setup.figures;
import junit.framework.Assert;
import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.RectangleFigure;
public abstract class FigureCheck extends Assert {
public static final FigureCheck CHECK_CAN_CREATE_INSTANCE = new FigureCheck(){
- public void checkFigure(IFigure figure) {
- //
+ protected void checkFigure(IFigure figure) {
+ Assert.assertNotNull(figure);
}
};
-
- public static FigureCheck combineChecks(final FigureCheck[] checks){
- assertNotNull(checks);
- assertTrue(checks.length > 0);
-
- return new FigureCheck(){
- public IFigure instantiateFigure(Class figureClass) {
- //can not instantiate twice
- return checks[0].instantiateFigure(figureClass);
- }
-
- public void checkFigure(IFigure figure) {
- for (int i = 0; i < checks.length; i++){
- checks[i].checkFigure(figure);
- }
- }
- };
+
+ private FigureCheck next;
+
+ /**
+ * Allows both
+ * c1.chain(c2).chain(c3)
+ * and
+ * c1.chain(c2.chain(c3)).chain(c4);
+ * @return this, head of the chain
+ */
+ public final FigureCheck chain(FigureCheck next) {
+ Assert.assertFalse(this == next);
+ FigureCheck last = this;
+ while (last.next != null) {
+ last = last.next;
+ }
+ last.next = next;
+ return this;
}
-
- public static FigureCheck combineChecks(FigureCheck first, FigureCheck second){
- return combineChecks(new FigureCheck[] {first, second});
+
+ public final void go(Class figureClass) {
+ IFigure figure = instantiateFigure(figureClass);
+ assertNotNull(figure);
+ go(figure);
+ }
+
+ public final void go(IFigure figure) {
+ checkFigure(figure);
+ if (next != null) {
+ next.go(figure);
+ }
}
/**
* Overridable to allow not default construction
*/
- public IFigure instantiateFigure(Class figureClass) {
+ protected IFigure instantiateFigure(Class figureClass) {
Object result = null;
try {
result = figureClass.newInstance();
- } catch (InstantiationException e) {
- fail(e.getMessage());
- } catch (IllegalAccessException e) {
- fail(e.getMessage());
+ } catch (Exception e) {
+ fail(e.getClass().getSimpleName() + ":" + e.getMessage());
}
- assertNotNull(result);
assertTrue(figureClass.getName(), result instanceof IFigure);
return (IFigure) result;
}
- public abstract void checkFigure(IFigure figure);
+ protected abstract void checkFigure(IFigure figure);
} \ No newline at end of file
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/FigureGeneratorUtil.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/FigureGeneratorUtil.java
index 12f737c7b..4c01bc253 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/FigureGeneratorUtil.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/FigureGeneratorUtil.java
@@ -21,7 +21,6 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.draw2d.IFigure;
import org.eclipse.emf.codegen.util.CodeGenUtil;
import org.eclipse.gmf.common.codegen.ImportAssistant;
import org.eclipse.gmf.gmfgraph.BasicFont;
@@ -64,6 +63,7 @@ public class FigureGeneratorUtil {
// FigureGenerator: utility methods to generate/compile/instantiate figures
public static void performTests(Figure f, FigureCheck check, Config config) {
+ Assert.assertNotNull(check);
generateAndParse(f);
FigureGallery gallery = GMFGraphFactory.eINSTANCE.createFigureGallery();
gallery.setName("bb");
@@ -73,11 +73,7 @@ public class FigureGeneratorUtil {
Assert.assertNotNull(theOnly);
Assert.assertEquals(1, theOnly.length);
Class figureClass = theOnly[0].getLoadedClass();
- if (check != null){
- IFigure figure = check.instantiateFigure(figureClass);
- Assert.assertNotNull(figure);
- check.checkFigure(figure);
- }
+ check.go(figureClass);
}
public static void generate(StandaloneGenerator.Config config, Processor processor) {
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/GenericFigureCheck.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/GenericFigureCheck.java
index 209ea9179..c21d92f6a 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/GenericFigureCheck.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/GenericFigureCheck.java
@@ -60,7 +60,7 @@ public class GenericFigureCheck extends FigureCheck {
myGMFRootFigure = eFigure;
}
- public void checkFigure(IFigure figure) {
+ protected void checkFigure(IFigure figure) {
assertNotNull(figure);
checkFigure(myGMFRootFigure, figure);
}

Back to the top