EMMA Coverage Report (generated Tue Feb 12 22:23:49 ICT 2008)
[all classes][net.sourceforge.hiveutils.test]

COVERAGE SUMMARY FOR SOURCE FILE [HivemindUnitTestCase.java]

nameclass, %method, %block, %line, %
HivemindUnitTestCase.java100% (1/1)100% (7/7)96%  (48/50)93%  (13/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class HivemindUnitTestCase100% (1/1)100% (7/7)96%  (48/50)93%  (13/14)
getArgument (String): Object 100% (1/1)85%  (11/13)75%  (3/4)
HivemindUnitTestCase (): void 100% (1/1)100% (3/3)100% (1/1)
defaultReturn (): Stub 100% (1/1)100% (4/4)100% (1/1)
isnull (): Constraint 100% (1/1)100% (4/4)100% (1/1)
runBare (): void 100% (1/1)100% (8/8)100% (3/3)
save (String): Constraint 100% (1/1)100% (5/5)100% (1/1)
save (String, Constraint): Constraint 100% (1/1)100% (13/13)100% (3/3)

1//  Copyright 2004-2007 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package net.sourceforge.hiveutils.test;
16 
17import java.util.HashMap;
18import java.util.Map;
19 
20import org.jmock.cglib.MockObjectTestCase;
21import org.jmock.core.Constraint;
22import org.jmock.core.Stub;
23import org.jmock.core.constraint.IsNull;
24import org.jmock.core.stub.DefaultResultStub;
25 
26/**
27 * Utility class that test cases can inherit in order to have better support
28 * (additional "syntactic sugar") for jMock usage.
29 *
30 * @author Jean-Francois Poilpret
31 */
32public class HivemindUnitTestCase extends MockObjectTestCase
33{
34        /**
35         * Overridden to reset the list of arguments values retained by the
36         * <code>save</code> methods.
37         */
38        //CSOFF: IllegalThrowsCheck
39        public void runBare() throws Throwable
40        {
41                _savedArgs = new HashMap<String, SaveConstraint>();
42                super.runBare();
43        }
44        //CSON: IllegalThrowsCheck
45 
46        /**
47         * Return the value of an argument provided to a <code>Mock</code> object's
48         * method and saved thanks to a <code>SaveConstraint</code>.
49         * @param name name under which the argument was saved
50         * @return last value saved for this argument, or <code>null</code> if there
51         * was no argument saved under this name
52         */        
53        protected Object                getArgument(String name)
54        {
55                SaveConstraint constraint = _savedArgs.get(name);
56                if (constraint != null)
57                {
58                        return constraint.getArgument();
59                }
60                else
61                {
62                        return null;
63                }
64        }
65 
66        /**
67         * Creates a <code>Constraint</code> that is used in the description of the
68         * expected argument to mocked method, and that needs to be saved under a
69         * name for later use in the same test case.
70         * @param name name under which the argument's value will be saved
71         * @return a Constraint that can be used in the <code>with</code> method
72         */                
73        protected Constraint        save(String name)
74        {
75                return save(name, null);
76        }
77        
78        /**
79         * Creates a <code>Constraint</code> that is used in the description of the
80         * expected argument to mocked method, and that needs to be saved under a
81         * name for later use in the same test case.
82         * @param name name under which the argument's value will be saved
83         * @param inner a real constraint that will be checked by jMock on the
84         * argument's value
85         * @return a Constraint that can be used in the <code>with</code> method
86         */                
87        protected Constraint        save(String name, Constraint inner)
88        {
89                SaveConstraint outer = new SaveConstraint(inner);
90                _savedArgs.put(name, outer);
91                return outer;
92        }
93 
94        /**
95         * Syntactic sugar to create an <code>IsNull</code> Constraint.
96         */
97        protected Constraint        isnull()
98        {
99                return new IsNull();
100        }
101        
102        /**
103         * Returns a <code>Stub</code> that produces a default return value. This
104         * is simply syntactic sugar around <code>new DefaultResultStub()</code>.
105         * @return stub returning a default value for a mocked method
106         */        
107        protected Stub        defaultReturn()
108        {
109                return new DefaultResultStub();
110        }
111        
112        private Map<String, SaveConstraint>        _savedArgs;
113}

[all classes][net.sourceforge.hiveutils.test]
EMMA 2.0.5312 (C) Vladimir Roubtsov