Author: kono
Date: 2010-10-21 17:25:58 -0700 (Thu, 21 Oct 2010)
New Revision: 22343

Added:
   
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/PresentationEventsTest.java
   
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/RenderingEngineManagerTest.java
   
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/VisualPropertyTest.java
   
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/VisualPropertyUtilTest.java
Modified:
   core3/presentation-api/trunk/pom.xml
   
core3/presentation-api/trunk/src/main/java/org/cytoscape/view/presentation/events/PresentationDestroyedEvent.java
   
core3/presentation-api/trunk/src/main/java/org/cytoscape/view/presentation/internal/RenderingEngineManagerImpl.java
Log:
Tests are added.

Modified: core3/presentation-api/trunk/pom.xml
===================================================================
--- core3/presentation-api/trunk/pom.xml        2010-10-22 00:03:55 UTC (rev 
22342)
+++ core3/presentation-api/trunk/pom.xml        2010-10-22 00:25:58 UTC (rev 
22343)
@@ -97,6 +97,12 @@
                        <scope>test</scope>
                </dependency>
                <dependency>
+                       <groupId>org.easymock</groupId>
+                       <artifactId>easymock</artifactId>
+                       <version>${easymock.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
                        <groupId>org.cytoscape</groupId>
                        <artifactId>viewmodel-impl</artifactId>
                        <version>1.0-SNAPSHOT</version>

Modified: 
core3/presentation-api/trunk/src/main/java/org/cytoscape/view/presentation/events/PresentationDestroyedEvent.java
===================================================================
--- 
core3/presentation-api/trunk/src/main/java/org/cytoscape/view/presentation/events/PresentationDestroyedEvent.java
   2010-10-22 00:03:55 UTC (rev 22342)
+++ 
core3/presentation-api/trunk/src/main/java/org/cytoscape/view/presentation/events/PresentationDestroyedEvent.java
   2010-10-22 00:25:58 UTC (rev 22343)
@@ -7,10 +7,10 @@
  * When presentation (rendered graphics) is destroyed, this event should be 
fired.
  *
  */
-public class PresentationDestroyedEvent extends 
AbstractCyEvent<RenderingEngine<?>> {
+public final class PresentationDestroyedEvent extends 
AbstractCyEvent<RenderingEngine<?>> {
 
        /**
-        * Construct an event for restroyed {...@linkplain RenderingEngine}.
+        * Construct an event for destroyed {...@linkplain RenderingEngine}.
         * 
         * @param source RenderingEngine for the deleted presentation.
         */

Modified: 
core3/presentation-api/trunk/src/main/java/org/cytoscape/view/presentation/internal/RenderingEngineManagerImpl.java
===================================================================
--- 
core3/presentation-api/trunk/src/main/java/org/cytoscape/view/presentation/internal/RenderingEngineManagerImpl.java
 2010-10-22 00:03:55 UTC (rev 22342)
+++ 
core3/presentation-api/trunk/src/main/java/org/cytoscape/view/presentation/internal/RenderingEngineManagerImpl.java
 2010-10-22 00:25:58 UTC (rev 22343)
@@ -27,36 +27,43 @@
                this.renderingEngineMap = new HashMap<View<?>, 
Set<RenderingEngine<?>>>();
        }
 
+       /**
+        * This method never returns null.
+        */
        @Override
-       public Collection<RenderingEngine<?>> getRendringEngines(
-                       final View<?> viewModel) {
-               return renderingEngineMap.get(viewModel);
+       public Collection<RenderingEngine<?>> getRendringEngines(final View<?> 
viewModel) {
+               Collection<RenderingEngine<?>> engines = 
renderingEngineMap.get(viewModel);
+               if(engines == null)
+                       engines = new HashSet<RenderingEngine<?>>();
+               
+               return engines;
        }
 
        @Override
        public void handleEvent(PresentationCreatedEvent e) {
+               // This cannot be null.
                final RenderingEngine<?> renderingEngine = e.getSource();
-               if (renderingEngine == null)
-                       return;
 
+               final View<?> viewModel = renderingEngine.getViewModel();
                Set<RenderingEngine<?>> engines = renderingEngineMap
-                               .get(renderingEngine.getViewModel());
+                               .get(viewModel);
                if (engines == null)
                        engines = new HashSet<RenderingEngine<?>>();
 
                engines.add(renderingEngine);
-               this.renderingEngineMap.put(renderingEngine.getViewModel(), 
engines);
-
+               this.renderingEngineMap.put(viewModel, engines);
        }
 
        @Override
        public void handleEvent(PresentationDestroyedEvent e) {
+               // This cannot be null.
                final RenderingEngine<?> renderingEngine = e.getSource();
-               if (renderingEngine == null)
-                       return;
 
-               this.renderingEngineMap.remove(renderingEngine.getViewModel());
-
+               final View<?> viewModel = renderingEngine.getViewModel();
+               final Set<RenderingEngine<?>> engineSet = 
renderingEngineMap.get(viewModel);
+               
+               engineSet.remove(renderingEngine);
+               this.renderingEngineMap.put(viewModel, engineSet);
        }
 
 }

Added: 
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/PresentationEventsTest.java
===================================================================
--- 
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/PresentationEventsTest.java
                              (rev 0)
+++ 
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/PresentationEventsTest.java
      2010-10-22 00:25:58 UTC (rev 22343)
@@ -0,0 +1,35 @@
+package org.cytoscape.view.presentation;
+
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.view.presentation.events.PresentationCreatedEvent;
+import org.cytoscape.view.presentation.events.PresentationDestroyedEvent;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class PresentationEventsTest {
+
+       @Before
+       public void setUp() throws Exception {
+       }
+
+       @After
+       public void tearDown() throws Exception {
+       }
+       
+       @Test
+       public void testEvents() {
+               
+               final RenderingEngine<CyNetwork> engine = 
createMock(RenderingEngine.class);
+               final PresentationCreatedEvent createdEvent = new 
PresentationCreatedEvent(engine);
+               assertEquals(engine, createdEvent.getSource());
+               
+               final PresentationDestroyedEvent destroyedEvent = new 
PresentationDestroyedEvent(engine);
+               assertEquals(engine, destroyedEvent.getSource());
+       }
+
+}

Added: 
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/RenderingEngineManagerTest.java
===================================================================
--- 
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/RenderingEngineManagerTest.java
                          (rev 0)
+++ 
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/RenderingEngineManagerTest.java
  2010-10-22 00:25:58 UTC (rev 22343)
@@ -0,0 +1,92 @@
+package org.cytoscape.view.presentation;
+
+import static org.junit.Assert.*;
+import static org.easymock.EasyMock.*;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.presentation.events.PresentationCreatedEvent;
+import org.cytoscape.view.presentation.events.PresentationCreatedEventListener;
+import org.cytoscape.view.presentation.events.PresentationDestroyedEvent;
+import 
org.cytoscape.view.presentation.events.PresentationDestroyedEventListener;
+import org.cytoscape.view.presentation.internal.RenderingEngineManagerImpl;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RenderingEngineManagerTest {
+       
+       private RenderingEngineManager manager;
+
+       @Before
+       public void setUp() throws Exception {
+               
+               manager = new RenderingEngineManagerImpl();
+       }
+
+       @After
+       public void tearDown() throws Exception {
+       }
+
+       @Test
+       public void testRenderingEngineManagerImpl() {
+               assertNotNull(manager);
+       }
+
+       @Test
+       public void testGetRendringEngines() {
+               
+               // First, create mock view models.
+               final CyNetworkView networkView1 = 
createMock(CyNetworkView.class);
+               final CyNetworkView networkView2 = 
createMock(CyNetworkView.class);
+               
+               final RenderingEngine<CyNetwork> engine1 = 
createMock(RenderingEngine.class);
+               
+               final RenderingEngine<CyNetwork> engine2 = 
createMock(RenderingEngine.class);
+               
expect(engine2.getViewModel()).andReturn(networkView1).anyTimes();
+               replay(engine2);
+               final RenderingEngine<CyNetwork> engine3 = 
createMock(RenderingEngine.class);
+               
expect(engine3.getViewModel()).andReturn(networkView2).anyTimes();
+               replay(engine3);
+               
+               final Collection<RenderingEngine<?>> engineSet = 
manager.getRendringEngines(networkView1);
+               assertNotNull(engineSet);
+               assertEquals(0, engineSet.size());
+               
+               final PresentationCreatedEvent createdEvent1 = new 
PresentationCreatedEvent(engine1);
+               
+               
expect(engine1.getViewModel()).andReturn(networkView1).anyTimes();
+               replay(engine1);
+               
((PresentationCreatedEventListener)manager).handleEvent(createdEvent1);
+
+               assertEquals(1, 
manager.getRendringEngines(networkView1).size());
+               assertEquals(engine1, 
manager.getRendringEngines(networkView1).iterator().next());
+               
+               
+               // Remove from manager
+               final PresentationDestroyedEvent destroyEvent = new 
PresentationDestroyedEvent(engine1);
+               
((PresentationDestroyedEventListener)manager).handleEvent(destroyEvent);
+               
+               assertEquals(0, 
manager.getRendringEngines(networkView1).size());
+               assertTrue(manager.getRendringEngines(networkView1) instanceof 
Set);
+               
+               // Add multiple engines
+               final PresentationCreatedEvent createdEvent2 = new 
PresentationCreatedEvent(engine2);
+               final PresentationCreatedEvent createdEvent3 = new 
PresentationCreatedEvent(engine3);
+               
((PresentationCreatedEventListener)manager).handleEvent(createdEvent2);
+               
((PresentationCreatedEventListener)manager).handleEvent(createdEvent1);
+               
((PresentationCreatedEventListener)manager).handleEvent(createdEvent3);
+               
+               assertEquals(2, 
manager.getRendringEngines(networkView1).size());
+               assertEquals(1, 
manager.getRendringEngines(networkView2).size());
+               
+               
assertTrue(manager.getRendringEngines(networkView1).contains(engine1));
+               
assertTrue(manager.getRendringEngines(networkView1).contains(engine2));
+               
assertTrue(manager.getRendringEngines(networkView2).contains(engine3));
+               
+       }
+
+}

Added: 
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/VisualPropertyTest.java
===================================================================
--- 
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/VisualPropertyTest.java
                          (rev 0)
+++ 
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/VisualPropertyTest.java
  2010-10-22 00:25:58 UTC (rev 22343)
@@ -0,0 +1,45 @@
+package org.cytoscape.view.presentation;
+
+
+import static org.junit.Assert.*;
+
+import java.awt.Color;
+
+import org.cytoscape.view.model.VisualProperty;
+import org.cytoscape.view.presentation.property.PaintVisualProperty;
+import org.cytoscape.view.presentation.property.TwoDVisualLexicon;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class VisualPropertyTest {
+
+       @Before
+       public void setUp() throws Exception {
+       }
+
+       @After
+       public void tearDown() throws Exception {
+       }
+       
+       @Test
+       public void testVisualProperties() {
+               final VisualProperty<Color> colorProp = 
TwoDVisualLexicon.NODE_COLOR;
+               assertEquals(Color.class, colorProp.getType());
+               
+               final VisualProperty<Boolean> booleanProp = 
TwoDVisualLexicon.NODE_VISIBLE;
+               assertEquals(Boolean.class, booleanProp.getType());
+               assertEquals("false", 
booleanProp.toSerializableString(Boolean.FALSE));
+               assertEquals(false, 
booleanProp.parseSerializableString("false"));
+               assertEquals(false, 
booleanProp.parseSerializableString("False"));
+               assertEquals(false, 
booleanProp.parseSerializableString("FALSE"));
+               
+               final VisualProperty<Double> doubleProp = 
TwoDVisualLexicon.NODE_SIZE;
+               assertEquals(Boolean.class, booleanProp.getType());
+               assertEquals("false", 
booleanProp.toSerializableString(Boolean.FALSE));
+               assertEquals(false, 
booleanProp.parseSerializableString("false"));
+               assertEquals(false, 
booleanProp.parseSerializableString("False"));
+               assertEquals(false, 
booleanProp.parseSerializableString("FALSE"));
+       }
+
+}

Added: 
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/VisualPropertyUtilTest.java
===================================================================
--- 
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/VisualPropertyUtilTest.java
                              (rev 0)
+++ 
core3/presentation-api/trunk/src/test/java/org/cytoscape/view/presentation/VisualPropertyUtilTest.java
      2010-10-22 00:25:58 UTC (rev 22343)
@@ -0,0 +1,23 @@
+package org.cytoscape.view.presentation;
+
+import static org.junit.Assert.*;
+
+import org.cytoscape.view.model.VisualLexicon;
+import org.cytoscape.view.presentation.property.TwoDVisualLexicon;
+import org.cytoscape.view.presentation.property.VisualPropertyUtil;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class VisualPropertyUtilTest {
+
+
+       @Test
+       public void testIsChildOf() {
+       }
+
+       @Test
+       public void testGetGraphObjectType() {
+       }
+
+}

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