Author: ruschein
Date: 2010-09-03 14:23:07 -0700 (Fri, 03 Sep 2010)
New Revision: 21693
Added:
core3/work-api/trunk/src/test/java/org/cytoscape/work/AbstractTunableInterceptorTest.java
core3/work-api/trunk/src/test/java/org/cytoscape/work/HasAnnotatedField.java
core3/work-api/trunk/src/test/java/org/cytoscape/work/ProvidesGUIExample.java
core3/work-api/trunk/src/test/java/org/cytoscape/work/SuperTaskTest.java
Modified:
core3/work-api/trunk/src/test/java/org/cytoscape/work/TunableHandlerTest.java
core3/work-api/trunk/src/test/java/org/cytoscape/work/undo/SimpleUndoableEditTest.java
Log:
Improved test coverage.
Added:
core3/work-api/trunk/src/test/java/org/cytoscape/work/AbstractTunableInterceptorTest.java
===================================================================
---
core3/work-api/trunk/src/test/java/org/cytoscape/work/AbstractTunableInterceptorTest.java
(rev 0)
+++
core3/work-api/trunk/src/test/java/org/cytoscape/work/AbstractTunableInterceptorTest.java
2010-09-03 21:23:07 UTC (rev 21693)
@@ -0,0 +1,180 @@
+/*
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.work;
+
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.swing.JPanel;
+
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.mockito.Mockito.*;
+
+
+public class AbstractTunableInterceptorTest {
+ private TunableInterceptor interceptor;
+ private HasAnnotatedField hasAnnotatedField;
+ private HasAnnotatedSetterAndGetterMethods
hasAnnotatedSetterAndGetterMethods;
+ private ProvidesGUIExample providesGUI;
+
+ @Before
+ public void init() {
+ final HandlerFactory<AbstractTunableHandler> handlerFactory =
new SimpleHandlerFactory();
+ interceptor = new ConcreteTunableInterceptor(handlerFactory);
+ hasAnnotatedField = new HasAnnotatedField();
+ hasAnnotatedSetterAndGetterMethods = new
HasAnnotatedSetterAndGetterMethods();
+ providesGUI = new ProvidesGUIExample();
+
+ }
+
+ @Test
+ public final void testLoadTunables() {
+ interceptor.loadTunables(hasAnnotatedField);
+ interceptor.loadTunables(hasAnnotatedSetterAndGetterMethods);
+ interceptor.loadTunables(providesGUI);
+ }
+
+ @Test
+ public final void testHasTunables() {
+ assertTrue("Should have found tunables!",
interceptor.hasTunables(hasAnnotatedField));
+ assertTrue("Should have found tunables!",
interceptor.hasTunables(hasAnnotatedSetterAndGetterMethods));
+ assertTrue("Should have found tunables!",
interceptor.hasTunables(providesGUI));
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public final void testInvalidGetter() {
+ interceptor.loadTunables(new HasInvalidGetter());
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public final void testInvalidGetterReturnType() {
+ interceptor.loadTunables(new HasInvalidGetterReturnType());
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public final void testMisnamedGetter() {
+ interceptor.loadTunables(new HasMisnamedGetter());
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public final void testInvalidSetter() {
+ interceptor.loadTunables(new HasInvalidSetter());
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public final void testInvalidProvidesGUIReturnType() {
+ interceptor.loadTunables(new HasInvalidProvidesGUIMethod());
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public final void testInvalidProvidesGUIMethodWithArg() {
+ interceptor.loadTunables(new
HasInvalidProvidesGUIMethodWithArg());
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public final void testInvalidMultipleProvidesGUIMethods() {
+ interceptor.loadTunables(new Has2ProvidesGUIMethods());
+ }
+}
+
+
+class SimpleHandlerFactory implements HandlerFactory<AbstractTunableHandler> {
+ public AbstractTunableHandler getHandler(final Field field, final
Object instance, final Tunable tunable) {
+ return new AbstractTunableHandler(field, instance, tunable);
+ }
+
+ public AbstractTunableHandler getHandler(final Method setter, final
Method getter, final Object instance, final Tunable tunable) {
+ return new AbstractTunableHandler(setter, getter, instance,
tunable);
+ }
+}
+
+
+class ConcreteTunableInterceptor extends AbstractTunableInterceptor {
+ ConcreteTunableInterceptor(final HandlerFactory<AbstractTunableHandler>
handlerFactory) {
+ super(handlerFactory);
+ }
+
+ public boolean validateAndWriteBackTunables() {
+ return true;
+ }
+
+ public boolean execUI(Object... obs) {
+ return true;
+ }
+}
+
+
+class HasInvalidGetter {
+ @Tunable
+ public int getStuff(int i) { return -1; }
+}
+
+
+class HasMisnamedGetter {
+ @Tunable
+ public int stuff() { return -1; }
+}
+
+
+class HasInvalidGetterReturnType {
+ @Tunable
+ public StringBuilder getStuff() { return new StringBuilder(); }
+}
+
+
+class HasInvalidSetter {
+ @Tunable
+ public int getStuff() { return -1; }
+
+ public void setStuff() { }
+}
+
+
+class HasInvalidProvidesGUIMethod {
+ @ProvidesGUI
+ public void badReturnType() { }
+}
+
+
+class HasInvalidProvidesGUIMethodWithArg {
+ @ProvidesGUI
+ public JPanel bad(int i) { return null; }
+}
+
+
+class Has2ProvidesGUIMethods {
+ @ProvidesGUI
+ public JPanel providesGUI1() { return null; }
+
+ @ProvidesGUI
+ public JPanel providesGUI2() { return null; }
+}
Added:
core3/work-api/trunk/src/test/java/org/cytoscape/work/HasAnnotatedField.java
===================================================================
---
core3/work-api/trunk/src/test/java/org/cytoscape/work/HasAnnotatedField.java
(rev 0)
+++
core3/work-api/trunk/src/test/java/org/cytoscape/work/HasAnnotatedField.java
2010-09-03 21:23:07 UTC (rev 21693)
@@ -0,0 +1,36 @@
+/*
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.work;
+
+
+class HasAnnotatedField {
+ @Tunable(description="An annotated field", groups={"group1"},
dependsOn="Fred",
flags={Tunable.Param.slider,Tunable.Param.horizontal,Tunable.Param.vertical,Tunable.Param.uncollapsed,Tunable.Param.collapsed,Tunable.Param.network,Tunable.Param.session,Tunable.Param.attributes,Tunable.Param.hidden,Tunable.Param.displayed})
+ public int annotatedInt;
+
+ public int getAnnotatedInt() { return annotatedInt; }
+}
Added:
core3/work-api/trunk/src/test/java/org/cytoscape/work/ProvidesGUIExample.java
===================================================================
---
core3/work-api/trunk/src/test/java/org/cytoscape/work/ProvidesGUIExample.java
(rev 0)
+++
core3/work-api/trunk/src/test/java/org/cytoscape/work/ProvidesGUIExample.java
2010-09-03 21:23:07 UTC (rev 21693)
@@ -0,0 +1,37 @@
+/*
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.work;
+
+
+import javax.swing.JPanel;
+
+
+class ProvidesGUIExample {
+ @ProvidesGUI
+ public JPanel getGUI() { return new JPanel(); }
+}
Added: core3/work-api/trunk/src/test/java/org/cytoscape/work/SuperTaskTest.java
===================================================================
--- core3/work-api/trunk/src/test/java/org/cytoscape/work/SuperTaskTest.java
(rev 0)
+++ core3/work-api/trunk/src/test/java/org/cytoscape/work/SuperTaskTest.java
2010-09-03 21:23:07 UTC (rev 21693)
@@ -0,0 +1,85 @@
+/*
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.work;
+
+
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.mockito.Mockito.*;
+
+
+public class SuperTaskTest {
+ @Test
+ public final void testConstructor1() {
+ final Task t1 = mock(Task.class);
+ final Task t2 = mock(Task.class);
+ final Task t3 = mock(Task.class);
+ new SuperTask(t1, t2, t3);
+ }
+
+ @Test
+ public final void testConstructor2() {
+ final Task[] tasks = new Task[] { mock(Task.class),
mock(Task.class), mock(Task.class) };
+ final double[] weights = new double[] { 1.0, 2.0, 3.0 };
+ new SuperTask(tasks, weights);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public final void testWrongNumberOfWeights() {
+ final Task[] tasks = new Task[] { mock(Task.class),
mock(Task.class), mock(Task.class) };
+ final double[] weights = new double[] { 1.0, 2.0 };
+ new SuperTask(tasks, weights);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public final void testInvalidNegativeWeight() {
+ final Task[] tasks = new Task[] { mock(Task.class),
mock(Task.class), mock(Task.class) };
+ final double[] weights = new double[] { 1.0, 2.0, -3.0 };
+ new SuperTask(tasks, weights);
+ }
+
+ @Test
+ public final void testCancel() {
+ final Task[] tasks = new Task[] { mock(Task.class),
mock(Task.class), mock(Task.class) };
+ final double[] weights = new double[] { 1.0, 2.0, 3.0 };
+ final SuperTask superTask = new SuperTask(tasks, weights);
+ superTask.cancel();
+ assertTrue("Invalid cancellation state!",
superTask.cancelled());
+ }
+
+ @Test
+ public final void testRunAndSubTaskMonitor() throws Exception {
+ final Task[] tasks = new Task[] { mock(Task.class),
mock(Task.class), mock(Task.class) };
+ final double[] weights = new double[] { 1.0, 2.0, 3.0 };
+ final SuperTask superTask = new SuperTask(tasks, weights);
+ final TaskMonitor taskMonitor = mock(TaskMonitor.class);
+ superTask.run(taskMonitor);
+ }
+}
Modified:
core3/work-api/trunk/src/test/java/org/cytoscape/work/TunableHandlerTest.java
===================================================================
---
core3/work-api/trunk/src/test/java/org/cytoscape/work/TunableHandlerTest.java
2010-09-03 21:22:45 UTC (rev 21692)
+++
core3/work-api/trunk/src/test/java/org/cytoscape/work/TunableHandlerTest.java
2010-09-03 21:23:07 UTC (rev 21693)
@@ -30,6 +30,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.Arrays;
import static org.junit.Assert.*;
import org.junit.Before;
@@ -75,8 +76,8 @@
@Test
public final void testGetFlags() {
- assertArrayEquals("The flags property of the tunable of an
annotated field is not as expected!",
- new Tunable.Param[] { },
fieldHandler.getFlags());
+ assertTrue("The flags property of the tunable of an annotated
field is not as expected!",
+
Arrays.asList(fieldHandler.getFlags()).contains(Tunable.Param.collapsed));
assertArrayEquals("The flags property of the tunable of an
annotated getter/setter pair is not as expected!",
new Tunable.Param[] { },
getterAndSetterHandler.getFlags());
}
@@ -145,28 +146,6 @@
}
-class HasAnnotatedField {
- @Tunable(description="An annotated field", groups={"group1"},
dependsOn="Fred")
- public int annotatedInt;
-
- public int getAnnotatedInt() { return annotatedInt; }
-}
-
-
-class HasAnnotatedSetterAndGetterMethods {
- private int privateInt;
-
- public void setPrivateInt(final int newValue) {
- privateInt = newValue;
- }
-
- @Tunable(description="Annotated setters and getters",
groups={"group2"}, dependsOn="Bob")
- public int getPrivateInt() {
- return privateInt;
- }
-}
-
-
class SimpleTunableHandler extends AbstractTunableHandler {
public SimpleTunableHandler(final Field field, final Object instance,
final Tunable tunable) {
super(field, instance, tunable);
Modified:
core3/work-api/trunk/src/test/java/org/cytoscape/work/undo/SimpleUndoableEditTest.java
===================================================================
---
core3/work-api/trunk/src/test/java/org/cytoscape/work/undo/SimpleUndoableEditTest.java
2010-09-03 21:22:45 UTC (rev 21692)
+++
core3/work-api/trunk/src/test/java/org/cytoscape/work/undo/SimpleUndoableEditTest.java
2010-09-03 21:23:07 UTC (rev 21693)
@@ -31,6 +31,7 @@
import javax.swing.undo.UndoableEdit;
import org.junit.Before;
+import org.junit.Test;
import org.cytoscape.work.undo.AbstractUndoableEdit;
@@ -40,8 +41,8 @@
private int savedState;
class SimpleUndoableEdit extends AbstractUndoableEdit {
- SimpleUndoableEdit() {
- super("simple");
+ SimpleUndoableEdit(final String presentationName) {
+ super(presentationName);
}
public void undo() { --state; }
@@ -50,7 +51,7 @@
@Before
public void init() {
- undoableEdit = new SimpleUndoableEdit();
+ undoableEdit = new SimpleUndoableEdit("simple");
}
@Override
@@ -67,4 +68,9 @@
public boolean currentStateIsIdenticalToSavedState() {
return state == savedState;
}
+
+ @Test(expected=IllegalArgumentException.class)
+ public final void testNullConstructorArgument() {
+ new SimpleUndoableEdit(null);
+ }
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.