Coverage Report - com.jeantessier.dependency.TestBasicTraversal
 
Classes in this File Line Coverage Branch Coverage Complexity
TestBasicTraversal
100%
46/46
N/A
1
TestBasicTraversal$1
100%
3/3
N/A
1
TestBasicTraversal$2
100%
3/3
N/A
1
TestBasicTraversal$3
100%
3/3
N/A
1
TestBasicTraversal$4
100%
11/11
N/A
1
TestBasicTraversal$5
100%
11/11
N/A
1
TestBasicTraversal$6
100%
8/8
N/A
1
 
 1  
 /*
 2  
  *  Copyright (c) 2001-2009, Jean Tessier
 3  
  *  All rights reserved.
 4  
  *
 5  
  *  Redistribution and use in source and binary forms, with or without
 6  
  *  modification, are permitted provided that the following conditions
 7  
  *  are met:
 8  
  *
 9  
  *      * Redistributions of source code must retain the above copyright
 10  
  *        notice, this list of conditions and the following disclaimer.
 11  
  *
 12  
  *      * Redistributions in binary form must reproduce the above copyright
 13  
  *        notice, this list of conditions and the following disclaimer in the
 14  
  *        documentation and/or other materials provided with the distribution.
 15  
  *
 16  
  *      * Neither the name of Jean Tessier nor the names of his contributors
 17  
  *        may be used to endorse or promote products derived from this software
 18  
  *        without specific prior written permission.
 19  
  *
 20  
  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21  
  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22  
  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23  
  *  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
 24  
  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25  
  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26  
  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27  
  *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28  
  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29  
  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30  
  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31  
  */
 32  
 
 33  
 package com.jeantessier.dependency;
 34  
 
 35  
 import java.util.*;
 36  
 
 37  
 import org.jmock.*;
 38  
 import org.jmock.integration.junit4.*;
 39  
 import org.jmock.lib.legacy.*;
 40  
 import org.junit.*;
 41  
 import org.junit.runner.*;
 42  
 
 43  
 @RunWith(JMock.class)
 44  34
 public class TestBasicTraversal {
 45  
     private Mockery context;
 46  
 
 47  
     private Visitor delegate;
 48  
 
 49  
     private PackageNode packageNode;
 50  
     private ClassNode classNode;
 51  
     private FeatureNode featureNode;
 52  
 
 53  
     private BasicTraversal sut;
 54  
 
 55  
     @Before
 56  
     public void setUp() {
 57  12
         context = new Mockery();
 58  12
         context.setImposteriser(ClassImposteriser.INSTANCE);
 59  
 
 60  12
         delegate = context.mock(Visitor.class);
 61  
 
 62  12
         packageNode = context.mock(PackageNode.class);
 63  12
         classNode = context.mock(ClassNode.class);
 64  12
         featureNode = context.mock(FeatureNode.class);
 65  
 
 66  12
         sut = new BasicTraversal();
 67  12
         sut.setDelegate(delegate);
 68  12
     }
 69  
 
 70  
     @Test
 71  
     public void testTraverseNodes_CallsAcceptDelegateOnNodes() {
 72  1
         final Collection<PackageNode> nodes = Collections.singleton(packageNode);
 73  
 
 74  1
         context.checking(new Expectations() {{
 75  1
             one (packageNode).accept(delegate);
 76  1
         }});
 77  
 
 78  1
         sut.traverseNodes(nodes);
 79  1
     }
 80  
 
 81  
     @Test
 82  
     public void testTraverseInbound() {
 83  1
         final Collection<PackageNode> nodes = Collections.singleton(packageNode);
 84  
 
 85  1
         context.checking(new Expectations() {{
 86  1
             one (packageNode).acceptInbound(delegate);
 87  1
         }});
 88  
 
 89  1
         sut.traverseInbound(nodes);
 90  1
     }
 91  
 
 92  
     @Test
 93  
     public void testTraverseOutbound() {
 94  1
         final Collection<PackageNode> nodes = Collections.singleton(packageNode);
 95  
 
 96  1
         context.checking(new Expectations() {{
 97  1
             one (packageNode).acceptOutbound(delegate);
 98  1
         }});
 99  
 
 100  1
         sut.traverseOutbound(nodes);
 101  1
     }
 102  
 
 103  
     @Test
 104  
     public void testVisitPackageNode_DelegatesTraversalOfInboundsAndOutboundsAndClasses() {
 105  1
         final Collection<ClassNode> nodes = Collections.singleton(classNode);
 106  
 
 107  1
         context.checking(new Expectations() {{
 108  
             // Process inbounds
 109  1
             one (packageNode).getInboundDependencies();
 110  1
                 will(returnValue(nodes));
 111  1
             one (delegate).traverseInbound(nodes);
 112  
 
 113  
             // Process outbounds
 114  1
             one (packageNode).getOutboundDependencies();
 115  1
                 will(returnValue(nodes));
 116  1
             one (delegate).traverseOutbound(nodes);
 117  
 
 118  
             // Process classes
 119  1
             one (packageNode).getClasses();
 120  1
                 will(returnValue(nodes));
 121  1
             one (delegate).traverseNodes(nodes);
 122  1
         }});
 123  
 
 124  1
         sut.visitPackageNode(packageNode);
 125  1
     }
 126  
 
 127  
     @Test
 128  
     public void testVisitInboundPackageNode_DoesNothing() {
 129  1
         sut.visitInboundPackageNode(packageNode);
 130  1
     }
 131  
 
 132  
     @Test
 133  
     public void testVisitOutboundPackageNode_DoesNothing() {
 134  1
         sut.visitOutboundPackageNode(packageNode);
 135  1
     }
 136  
 
 137  
     @Test
 138  
     public void testVisitClassNode_DelegatesTraversalOfInboundsAndOutboundsAndClasses() {
 139  1
         final Collection<FeatureNode> nodes = Collections.singleton(featureNode);
 140  
 
 141  1
         context.checking(new Expectations() {{
 142  
             // Process inbounds
 143  1
             one (classNode).getInboundDependencies();
 144  1
                 will(returnValue(nodes));
 145  1
             one (delegate).traverseInbound(nodes);
 146  
 
 147  
             // Process outbounds
 148  1
             one (classNode).getOutboundDependencies();
 149  1
                 will(returnValue(nodes));
 150  1
             one (delegate).traverseOutbound(nodes);
 151  
 
 152  
             // Process features
 153  1
             one (classNode).getFeatures();
 154  1
                 will(returnValue(nodes));
 155  1
             one (delegate).traverseNodes(nodes);
 156  1
         }});
 157  
 
 158  1
         sut.visitClassNode(classNode);
 159  1
     }
 160  
 
 161  
     @Test
 162  
     public void testVisitInboundClassNode_DoesNothing() {
 163  1
         sut.visitInboundClassNode(classNode);
 164  1
     }
 165  
 
 166  
     @Test
 167  
     public void testVisitOutboundClassNode_DoesNothing() {
 168  1
         sut.visitOutboundClassNode(classNode);
 169  1
     }
 170  
 
 171  
     @Test
 172  
     public void testVisitFeatureNode_InScope() {
 173  1
         final Collection<ClassNode> nodes = Collections.singleton(classNode);
 174  
 
 175  1
         context.checking(new Expectations() {{
 176  
             // Process inbounds
 177  1
             one (featureNode).getInboundDependencies();
 178  1
                 will(returnValue(nodes));
 179  1
             one (delegate).traverseInbound(nodes);
 180  
 
 181  
             // Process outbounds
 182  1
             one (featureNode).getOutboundDependencies();
 183  1
                 will(returnValue(nodes));
 184  1
             one (delegate).traverseOutbound(nodes);
 185  1
         }});
 186  
 
 187  1
         sut.visitFeatureNode(featureNode);
 188  1
     }
 189  
 
 190  
     @Test
 191  
     public void testVisitInboundFeatureNode_DoesNothing() {
 192  1
         sut.visitInboundFeatureNode(featureNode);
 193  1
     }
 194  
 
 195  
     @Test
 196  
     public void testVisitOutboundFeatureNode_DoesNothing() {
 197  1
         sut.visitOutboundFeatureNode(featureNode);
 198  1
     }
 199  
 }