Coverage Report - com.jeantessier.dependency.TestSelectiveVisitor
 
Classes in this File Line Coverage Branch Coverage Complexity
TestSelectiveVisitor
100%
83/83
N/A
1
TestSelectiveVisitor$1
100%
5/5
N/A
1
TestSelectiveVisitor$10
100%
4/4
N/A
1
TestSelectiveVisitor$11
100%
5/5
N/A
1
TestSelectiveVisitor$12
100%
4/4
N/A
1
TestSelectiveVisitor$13
100%
5/5
N/A
1
TestSelectiveVisitor$14
100%
4/4
N/A
1
TestSelectiveVisitor$15
100%
5/5
N/A
1
TestSelectiveVisitor$16
100%
4/4
N/A
1
TestSelectiveVisitor$17
100%
5/5
N/A
1
TestSelectiveVisitor$18
100%
4/4
N/A
1
TestSelectiveVisitor$19
100%
5/5
N/A
1
TestSelectiveVisitor$2
100%
5/5
N/A
1
TestSelectiveVisitor$20
100%
4/4
N/A
1
TestSelectiveVisitor$21
100%
5/5
N/A
1
TestSelectiveVisitor$3
100%
5/5
N/A
1
TestSelectiveVisitor$4
100%
4/4
N/A
1
TestSelectiveVisitor$5
100%
5/5
N/A
1
TestSelectiveVisitor$6
100%
4/4
N/A
1
TestSelectiveVisitor$7
100%
5/5
N/A
1
TestSelectiveVisitor$8
100%
4/4
N/A
1
TestSelectiveVisitor$9
100%
5/5
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  81
 public class TestSelectiveVisitor {
 45  
     private Mockery context;
 46  
 
 47  
     private Visitor delegate;
 48  
     private TraversalStrategy strategy;
 49  
 
 50  
     private PackageNode packageNode;
 51  
     private ClassNode classNode;
 52  
     private FeatureNode featureNode;
 53  
 
 54  
     private SelectiveVisitor sut;
 55  
 
 56  
     @Before
 57  
     public void setUp() {
 58  21
         context = new Mockery();
 59  21
         context.setImposteriser(ClassImposteriser.INSTANCE);
 60  
 
 61  21
         delegate = context.mock(Visitor.class);
 62  21
         strategy = context.mock(TraversalStrategy.class);
 63  
 
 64  21
         packageNode = context.mock(PackageNode.class);
 65  21
         classNode = context.mock(ClassNode.class);
 66  21
         featureNode = context.mock(FeatureNode.class);
 67  
 
 68  21
         sut = new SelectiveVisitor(strategy);
 69  21
         sut.setDelegate(delegate);
 70  21
     }
 71  
 
 72  
     @Test
 73  
     public void testTraverseNodes_SortsTheNodesUsingTheStrategy() {
 74  1
         final Collection<? extends Node> nodes = new ArrayList<Node>();
 75  1
         final Collection<Node> sortedNodes = new ArrayList<Node>();
 76  1
         sortedNodes.add(packageNode);
 77  
 
 78  1
         context.checking(new Expectations() {{
 79  1
             one (strategy).order(nodes);
 80  1
                 will(returnValue(sortedNodes));
 81  1
             one (delegate).traverseNodes(sortedNodes);
 82  1
         }});
 83  
 
 84  1
         sut.traverseNodes(nodes);
 85  1
     }
 86  
 
 87  
     @Test
 88  
     public void testTraverseInbound_SortsTheNodesUsingTheStrategy() {
 89  1
         final Collection<? extends Node> nodes = new ArrayList<Node>();
 90  1
         final Collection<Node> sortedNodes = new ArrayList<Node>();
 91  1
         sortedNodes.add(packageNode);
 92  
 
 93  1
         context.checking(new Expectations() {{
 94  1
             one (strategy).order(nodes);
 95  1
                 will(returnValue(sortedNodes));
 96  1
             one (delegate).traverseInbound(sortedNodes);
 97  1
         }});
 98  
 
 99  1
         sut.traverseInbound(nodes);
 100  1
     }
 101  
 
 102  
     @Test
 103  
     public void testTraverseOutbound_SortsTheNodesUsingTheStrategy() {
 104  1
         final Collection<? extends Node> nodes = new ArrayList<Node>();
 105  1
         final Collection<Node> sortedNodes = new ArrayList<Node>();
 106  1
         sortedNodes.add(packageNode);
 107  
 
 108  1
         context.checking(new Expectations() {{
 109  1
             one (strategy).order(nodes);
 110  1
                 will(returnValue(sortedNodes));
 111  1
             one (delegate).traverseOutbound(sortedNodes);
 112  1
         }});
 113  
 
 114  1
         sut.traverseOutbound(nodes);
 115  1
     }
 116  
 
 117  
     @Test
 118  
     public void testVisitPackageNode_NotInScope() {
 119  1
         context.checking(new Expectations() {{
 120  1
             one (strategy).isInScope(packageNode);
 121  1
                 will(returnValue(false));
 122  1
         }});
 123  
 
 124  1
         sut.visitPackageNode(packageNode);
 125  1
     }
 126  
 
 127  
     @Test
 128  
     public void testVisitPackageNode_InScope() {
 129  1
         context.checking(new Expectations() {{
 130  1
             one (strategy).isInScope(packageNode);
 131  1
                 will(returnValue(true));
 132  1
             one (packageNode).accept(delegate);
 133  1
         }});
 134  
 
 135  1
         sut.visitPackageNode(packageNode);
 136  1
     }
 137  
 
 138  
     @Test
 139  
     public void testVisitInboundPackageNode_NotInFilter() {
 140  1
         context.checking(new Expectations() {{
 141  1
             one (strategy).isInFilter(packageNode);
 142  1
                 will(returnValue(false));
 143  1
         }});
 144  
 
 145  1
         sut.visitInboundPackageNode(packageNode);
 146  1
     }
 147  
 
 148  
     @Test
 149  
     public void testVisitInboundPackageNode_InFilter() {
 150  1
         context.checking(new Expectations() {{
 151  1
             one (strategy).isInFilter(packageNode);
 152  1
                 will(returnValue(true));
 153  1
             one (packageNode).acceptInbound(delegate);
 154  1
         }});
 155  
 
 156  1
         sut.visitInboundPackageNode(packageNode);
 157  1
     }
 158  
 
 159  
     @Test
 160  
     public void testVisitOutboundPackageNode_NotInFilter() {
 161  1
         context.checking(new Expectations() {{
 162  1
             one (strategy).isInFilter(packageNode);
 163  1
                 will(returnValue(false));
 164  1
         }});
 165  
 
 166  1
         sut.visitOutboundPackageNode(packageNode);
 167  1
     }
 168  
 
 169  
     @Test
 170  
     public void testVisitOutboundPackageNode_InFilter() {
 171  1
         context.checking(new Expectations() {{
 172  1
             one (strategy).isInFilter(packageNode);
 173  1
                 will(returnValue(true));
 174  1
             one (packageNode).acceptOutbound(delegate);
 175  1
         }});
 176  
 
 177  1
         sut.visitOutboundPackageNode(packageNode);
 178  1
     }
 179  
 
 180  
     @Test
 181  
     public void testVisitClassNode_NotInScope() {
 182  1
         context.checking(new Expectations() {{
 183  1
             one (strategy).isInScope(classNode);
 184  1
                 will(returnValue(false));
 185  1
         }});
 186  
 
 187  1
         sut.visitClassNode(classNode);
 188  1
     }
 189  
 
 190  
     @Test
 191  
     public void testVisitClassNode_InScope() {
 192  1
         context.checking(new Expectations() {{
 193  1
             one (strategy).isInScope(classNode);
 194  1
                 will(returnValue(true));
 195  1
             one (classNode).accept(delegate);
 196  1
         }});
 197  
 
 198  1
         sut.visitClassNode(classNode);
 199  1
     }
 200  
 
 201  
     @Test
 202  
     public void testVisitInboundClassNode_NotInFilter() {
 203  1
         context.checking(new Expectations() {{
 204  1
             one (strategy).isInFilter(classNode);
 205  1
                 will(returnValue(false));
 206  1
         }});
 207  
 
 208  1
         sut.visitInboundClassNode(classNode);
 209  1
     }
 210  
 
 211  
     @Test
 212  
     public void testVisitInboundClassNode_InFilter() {
 213  1
         context.checking(new Expectations() {{
 214  1
             one (strategy).isInFilter(classNode);
 215  1
                 will(returnValue(true));
 216  1
             one (classNode).acceptInbound(delegate);
 217  1
         }});
 218  
 
 219  1
         sut.visitInboundClassNode(classNode);
 220  1
     }
 221  
 
 222  
     @Test
 223  
     public void testVisitOutboundClassNode_NotInFilter() {
 224  1
         context.checking(new Expectations() {{
 225  1
             one (strategy).isInFilter(classNode);
 226  1
                 will(returnValue(false));
 227  1
         }});
 228  
 
 229  1
         sut.visitOutboundClassNode(classNode);
 230  1
     }
 231  
 
 232  
     @Test
 233  
     public void testVisitOutboundClassNode_InFilter() {
 234  1
         context.checking(new Expectations() {{
 235  1
             one (strategy).isInFilter(classNode);
 236  1
                 will(returnValue(true));
 237  1
             one (classNode).acceptOutbound(delegate);
 238  1
         }});
 239  
 
 240  1
         sut.visitOutboundClassNode(classNode);
 241  1
     }
 242  
 
 243  
     @Test
 244  
     public void testVisitFeatureNode_NotInScope() {
 245  1
         context.checking(new Expectations() {{
 246  1
             one (strategy).isInScope(featureNode);
 247  1
                 will(returnValue(false));
 248  1
         }});
 249  
 
 250  1
         sut.visitFeatureNode(featureNode);
 251  1
     }
 252  
 
 253  
     @Test
 254  
     public void testVisitFeatureNode_InScope() {
 255  1
         context.checking(new Expectations() {{
 256  1
             one (strategy).isInScope(featureNode);
 257  1
                 will(returnValue(true));
 258  1
             one (featureNode).accept(delegate);
 259  1
         }});
 260  
 
 261  1
         sut.visitFeatureNode(featureNode);
 262  1
     }
 263  
 
 264  
     @Test
 265  
     public void testVisitInboundFeatureNode_NotInFilter() {
 266  1
         context.checking(new Expectations() {{
 267  1
             one (strategy).isInFilter(featureNode);
 268  1
                 will(returnValue(false));
 269  1
         }});
 270  
 
 271  1
         sut.visitInboundFeatureNode(featureNode);
 272  1
     }
 273  
 
 274  
     @Test
 275  
     public void testVisitInboundFeatureNode_InFilter() {
 276  1
         context.checking(new Expectations() {{
 277  1
             one (strategy).isInFilter(featureNode);
 278  1
                 will(returnValue(true));
 279  1
             one (featureNode).acceptInbound(delegate);
 280  1
         }});
 281  
 
 282  1
         sut.visitInboundFeatureNode(featureNode);
 283  1
     }
 284  
 
 285  
     @Test
 286  
     public void testVisitOutboundFeatureNode_NotInFilter() {
 287  1
         context.checking(new Expectations() {{
 288  1
             one (strategy).isInFilter(featureNode);
 289  1
                 will(returnValue(false));
 290  1
         }});
 291  
 
 292  1
         sut.visitOutboundFeatureNode(featureNode);
 293  1
     }
 294  
 
 295  
     @Test
 296  
     public void testVisitOutboundFeatureNode_InFilter() {
 297  1
         context.checking(new Expectations() {{
 298  1
             one (strategy).isInFilter(featureNode);
 299  1
                 will(returnValue(true));
 300  1
             one (featureNode).acceptOutbound(delegate);
 301  1
         }});
 302  
 
 303  1
         sut.visitOutboundFeatureNode(featureNode);
 304  1
     }
 305  
 }