Author: ruschein
Date: 2010-08-13 11:10:44 -0700 (Fri, 13 Aug 2010)
New Revision: 21379

Added:
   core3/work-api/trunk/src/test/
   core3/work-api/trunk/src/test/java/
   core3/work-api/trunk/src/test/java/org/
   core3/work-api/trunk/src/test/java/org/cytoscape/
   core3/work-api/trunk/src/test/java/org/cytoscape/work/
   core3/work-api/trunk/src/test/java/org/cytoscape/work/undo/
   
core3/work-api/trunk/src/test/java/org/cytoscape/work/undo/AbstractUndoableEditTest.java
   
core3/work-api/trunk/src/test/java/org/cytoscape/work/undo/SimpleUndoableEditTest.java
Modified:
   core3/work-api/trunk/pom.xml
   
core3/work-api/trunk/src/main/java/org/cytoscape/work/undo/AbstractUndoableEdit.java
Log:
Added unit tests.

Modified: core3/work-api/trunk/pom.xml
===================================================================
--- core3/work-api/trunk/pom.xml        2010-08-13 14:47:55 UTC (rev 21378)
+++ core3/work-api/trunk/pom.xml        2010-08-13 18:10:44 UTC (rev 21379)
@@ -92,6 +92,25 @@
           </instructions>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>${junit.version}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
 </project>

Modified: 
core3/work-api/trunk/src/main/java/org/cytoscape/work/undo/AbstractUndoableEdit.java
===================================================================
--- 
core3/work-api/trunk/src/main/java/org/cytoscape/work/undo/AbstractUndoableEdit.java
        2010-08-13 14:47:55 UTC (rev 21378)
+++ 
core3/work-api/trunk/src/main/java/org/cytoscape/work/undo/AbstractUndoableEdit.java
        2010-08-13 18:10:44 UTC (rev 21379)
@@ -43,6 +43,9 @@
        private final String presentationName;
 
        public AbstractUndoableEdit(final String presentationName) {
+               if (presentationName == null)
+                       throw new IllegalArgumentException("in call to 
AbstractUndoableEdit(), presentationName must not be null!");
+
                this.presentationName = presentationName;
        }
 

Added: 
core3/work-api/trunk/src/test/java/org/cytoscape/work/undo/AbstractUndoableEditTest.java
===================================================================
--- 
core3/work-api/trunk/src/test/java/org/cytoscape/work/undo/AbstractUndoableEditTest.java
                            (rev 0)
+++ 
core3/work-api/trunk/src/test/java/org/cytoscape/work/undo/AbstractUndoableEditTest.java
    2010-08-13 18:10:44 UTC (rev 21379)
@@ -0,0 +1,70 @@
+/*
+ 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.undo;
+
+
+import javax.swing.undo.UndoableEdit;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+import org.cytoscape.work.undo.AbstractUndoableEdit;
+
+
+public abstract class AbstractUndoableEditTest {
+       protected UndoableEdit undoableEdit;
+
+       public abstract void saveState();
+       public abstract void changeState();
+       public abstract boolean currentStateIsIdenticalToSavedState();
+
+       @Test
+       public final void testPresentationName() {
+               assertTrue("presentation name is non-empty", 
!undoableEdit.getPresentationName().isEmpty());
+               assertTrue("redo presentation name is non-empty", 
!undoableEdit.getRedoPresentationName().isEmpty());
+               assertTrue("undo presentation name is non-empty", 
!undoableEdit.getUndoPresentationName().isEmpty());
+               assertTrue("redo and undo presentation name are different", 
undoableEdit.getRedoPresentationName() != 
undoableEdit.getUndoPresentationName());
+       }
+
+       @Test
+       public final void testUndo() {
+               saveState();
+               changeState();
+               undoableEdit.undo();
+               assertTrue("state is back to orginal after undo", 
currentStateIsIdenticalToSavedState());
+       }
+
+       @Test
+       public final void testRedo() {
+               saveState();
+               changeState();
+               undoableEdit.undo();
+               undoableEdit.redo();
+               assertTrue("state is different from orginal after undo followed 
by redo", !currentStateIsIdenticalToSavedState());
+       }
+}

Added: 
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
                              (rev 0)
+++ 
core3/work-api/trunk/src/test/java/org/cytoscape/work/undo/SimpleUndoableEditTest.java
      2010-08-13 18:10:44 UTC (rev 21379)
@@ -0,0 +1,70 @@
+/*
+ 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.undo;
+
+
+import javax.swing.undo.UndoableEdit;
+
+import org.junit.Before;
+
+import org.cytoscape.work.undo.AbstractUndoableEdit;
+
+
+public class SimpleUndoableEditTest extends AbstractUndoableEditTest {
+       private int state = 0;
+       private int savedState;
+
+       class SimpleUndoableEdit extends AbstractUndoableEdit {
+               SimpleUndoableEdit() {
+                       super("simple");
+               }
+
+               public void undo() { --state; }
+               public void redo() { ++state; }
+       }
+
+       @Before
+       public void setUp() {
+               undoableEdit = new SimpleUndoableEdit();
+       }
+
+       @Override
+       public void saveState() {
+               savedState = state;
+       }
+
+       @Override
+       public void changeState() {
+               ++state;
+       }
+
+       @Override
+       public boolean currentStateIsIdenticalToSavedState() {
+               return state == savedState;
+       }
+}

-- 
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.

Reply via email to