Coverage Report - net.sourceforge.combean.test.graph.util.TestGraphPropertyInitializer
 
Classes in this File Line Coverage Branch Coverage Complexity
TestGraphPropertyInitializer
87%
39/45
N/A
1,286
TestGraphPropertyInitializer$AlgNeedingAlsoConstruction
67%
2/3
0%
0/2
1,286
TestGraphPropertyInitializer$AlgNeedingNeighborhoodAndGlobalNodes
92%
11/12
N/A
1,286
TestGraphPropertyInitializer$AlgNeedingNothing
50%
1/2
N/A
1,286
 
 1  
 /*
 2  
     This file is part of Combean.
 3  
 
 4  
     Combean is free software; you can redistribute it and/or modify
 5  
     it under the terms of the GNU General Public License as published by
 6  
     the Free Software Foundation; either version 2 of the License, or
 7  
     (at your option) any later version.
 8  
 
 9  
     Combean is distributed in the hope that it will be useful,
 10  
     but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  
     GNU General Public License for more details.
 13  
 
 14  
     You should have received a copy of the GNU General Public License
 15  
     along with Combean; if not, write to the Free Software
 16  
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 17  
 */
 18  
 /*
 19  
  * Created on 19.03.2005
 20  
  *
 21  
  */
 22  
 package net.sourceforge.combean.test.graph.util;
 23  
 
 24  
 import junit.framework.TestCase;
 25  
 import net.sourceforge.combean.adapters.drasys.graph.DRAGraphWithEditIAsGraph;
 26  
 import net.sourceforge.combean.graph.alg.AbstractGraphAlg;
 27  
 import net.sourceforge.combean.graph.decorators.TransposedGraph;
 28  
 import net.sourceforge.combean.graph.except.UnsupportedGraphProperty;
 29  
 import net.sourceforge.combean.interfaces.graph.Graph;
 30  
 import net.sourceforge.combean.interfaces.graph.prop.ConstructableGraphProp;
 31  
 import net.sourceforge.combean.interfaces.graph.prop.DirectedEdgeNeighborhoodGraphProp;
 32  
 import net.sourceforge.combean.interfaces.graph.prop.GlobalNodesGraphProp;
 33  
 import net.sourceforge.combean.interfaces.graph.prop.NeighborhoodGraphProp;
 34  
 import net.sourceforge.combean.test.helpers.stubs.GraphWithoutProperties;
 35  
 import net.sourceforge.combean.util.except.UnsupportedMethodException;
 36  
 
 37  
 /**
 38  
  * @author schickin
 39  
  *
 40  
  */
 41  
 public class TestGraphPropertyInitializer extends TestCase {
 42  
     
 43  15
     private GraphWithoutProperties noPropGraph = null;
 44  15
     private DRAGraphWithEditIAsGraph draGraph = null;
 45  15
     private DirectedEdgeNeighborhoodGraphProp transposedGraph = null;
 46  15
     private DirectedEdgeNeighborhoodGraphProp doubleTransposedGraph = null;
 47  
     
 48  15
     private AlgNeedingNothing algNeedingNothing = null;
 49  15
     private AlgNeedingNeighborhoodAndGlobalNodes algNeedingSomething = null;
 50  15
     private AlgNeedingAlsoConstruction algNeedingAlsoConstr = null;
 51  
     
 52  15
     protected class AlgNeedingNothing extends AbstractGraphAlg {
 53  
         
 54  
         /* (non-Javadoc)
 55  
          * @see net.sourceforge.combean.interfaces.graph.alg.GraphAlgorithm#run()
 56  
          */
 57  
         public void run() {
 58  0
             throw new UnsupportedMethodException();
 59  
         }
 60  
     }
 61  
     
 62  30
     protected class AlgNeedingNeighborhoodAndGlobalNodes extends AbstractGraphAlg {
 63  
         
 64  30
         private NeighborhoodGraphProp neigh = null;
 65  30
         private GlobalNodesGraphProp globNodes = null;
 66  
         
 67  
         /* (non-Javadoc)
 68  
          * @see net.sourceforge.combean.interfaces.graph.alg.GraphAlgorithm#run()
 69  
          */
 70  
         public void run() {
 71  0
             throw new UnsupportedMethodException();
 72  
         }
 73  
         
 74  
         public void checkIfGraphIsSet(Graph g) {
 75  3
             assertEquals(g, this.neigh);
 76  3
             assertEquals(g, this.globNodes);
 77  3
             assertEquals(g, getGraph());
 78  3
         }
 79  
         
 80  
         public void checkIfNestedGraphIsSet(Graph g, Graph innerG) {
 81  6
             assertEquals(g, this.neigh);
 82  6
             assertEquals(innerG, this.globNodes);
 83  6
             assertEquals(g, getGraph());
 84  6
         }
 85  
     }
 86  
     
 87  30
     protected class AlgNeedingAlsoConstruction
 88  
     extends AlgNeedingNeighborhoodAndGlobalNodes {
 89  15
         private ConstructableGraphProp constructableG = null;
 90  
         
 91  0
         boolean foo() { return this.constructableG == null; };
 92  
     }
 93  
 
 94  
     public static void main(String[] args) {
 95  0
         junit.textui.TestRunner.run(TestGraphPropertyInitializer.class);
 96  0
     }
 97  
 
 98  
     /*
 99  
      * @see TestCase#setUp()
 100  
      */
 101  
     protected void setUp() throws Exception {
 102  15
         super.setUp();
 103  
         
 104  15
         this.noPropGraph = new GraphWithoutProperties();
 105  15
         this.draGraph = new DRAGraphWithEditIAsGraph();
 106  15
         this.transposedGraph = new TransposedGraph(this.draGraph);
 107  15
         this.doubleTransposedGraph = new TransposedGraph(this.transposedGraph);
 108  
         
 109  15
         this.algNeedingNothing = new AlgNeedingNothing();
 110  15
         this.algNeedingSomething = new AlgNeedingNeighborhoodAndGlobalNodes();
 111  15
         this.algNeedingAlsoConstr = new AlgNeedingAlsoConstruction();
 112  15
     }
 113  
 
 114  
     /*
 115  
      * @see TestCase#tearDown()
 116  
      */
 117  
     protected void tearDown() throws Exception {
 118  15
         super.tearDown();
 119  15
     }
 120  
 
 121  
     /**
 122  
      * Constructor for TestGraphPropertyInitializer.
 123  
      * @param name
 124  
      */
 125  
     public TestGraphPropertyInitializer(String name) {
 126  15
         super(name);
 127  15
     }
 128  
 
 129  
     public final void testSetGraphOnAlgNeedingNothing() {
 130  3
         this.algNeedingNothing.setGraph(this.noPropGraph); 
 131  3
         assertEquals(this.noPropGraph, this.algNeedingNothing.getGraph());
 132  
 
 133  3
         this.algNeedingNothing.setGraph(this.draGraph); 
 134  3
         assertEquals(this.draGraph, this.algNeedingNothing.getGraph());
 135  3
     }
 136  
 
 137  
     public final void testSetGraphOnAlgNeedingSomething() {
 138  
         try {
 139  3
             this.algNeedingSomething.setGraph(this.noPropGraph);
 140  0
             fail("exception should be thrown because graph does not have " +
 141  
                     "the required properties");
 142  
         }
 143  3
         catch (UnsupportedGraphProperty e) {
 144  
             /* ok, this exception was expected */
 145  0
         }
 146  
         
 147  3
         this.algNeedingSomething.setGraph(this.draGraph);
 148  3
         this.algNeedingSomething.checkIfGraphIsSet(this.draGraph);
 149  3
     }
 150  
     
 151  
     public final void testSetGraphOnNestedGraph() {
 152  3
         this.algNeedingSomething.setGraph(this.transposedGraph);
 153  3
         this.algNeedingSomething.checkIfNestedGraphIsSet(this.transposedGraph,
 154  
                 this.draGraph);
 155  3
     }
 156  
 
 157  
     public final void testSetGraphOnDoubleNestedGraph() {
 158  3
         this.algNeedingSomething.setGraph(this.doubleTransposedGraph);
 159  3
         this.algNeedingSomething.checkIfNestedGraphIsSet(
 160  
                 this.doubleTransposedGraph, this.draGraph);
 161  3
     }
 162  
 
 163  
     public final void testSetGraphWithPropertyNotVisibleThroughNestedGraph() {
 164  
         try {
 165  3
             this.algNeedingAlsoConstr.setGraph(this.transposedGraph);
 166  0
             fail("construction property must not be visible through transposed graph");
 167  
         }
 168  3
         catch (UnsupportedGraphProperty e) {
 169  
             /* ok, this exception was expected */
 170  0
         }
 171  3
     }
 172  
 }