|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
Null.java | - | 100% | 100% | 100% |
|
1 |
/* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
|
|
2 |
package org.jmock.expectation;
|
|
3 |
|
|
4 |
/**
|
|
5 |
* A class that represents the <code>null</code> value.
|
|
6 |
* The {@link org.jmock.expectation.Null Null} class is used when an
|
|
7 |
* {@link org.jmock.expectation.Expectation Expectation} is set to expect nothing.
|
|
8 |
* <p/>
|
|
9 |
* <b>Example usage:</b>
|
|
10 |
* <pre>
|
|
11 |
* public class MockX {
|
|
12 |
* private Expectation... anExpectation = new Expectation...(...);
|
|
13 |
* <p/>
|
|
14 |
* public MockX() {
|
|
15 |
* anExpectation.setExpectNothing();
|
|
16 |
* }
|
|
17 |
* <p/>
|
|
18 |
* public void setAnExpectation(Object value) {
|
|
19 |
* anExpectation.setExpected(value);
|
|
20 |
* }
|
|
21 |
* <p/>
|
|
22 |
* public void setActual(Object value) {
|
|
23 |
* anExpectation.setActual(value);
|
|
24 |
* }
|
|
25 |
* }
|
|
26 |
* </pre>
|
|
27 |
* The act of calling {@link org.jmock.expectation.Expectation#setExpectNothing() Expectation.setExpectNothing()}
|
|
28 |
* tells the expectation that it should expect no values to change. Since
|
|
29 |
* all {@link org.jmock.expectation.Null Null} objects are equal to themselves,
|
|
30 |
* most expectations set their expected value to an instance of
|
|
31 |
* {@link org.jmock.expectation.Null Null}, and at the same time, set their actual
|
|
32 |
* value to another instance of {@link org.jmock.expectation.Null Null}.
|
|
33 |
* This way, when {@link org.jmock.expectation.Verifiable#verify() verify()} checks
|
|
34 |
* expectations, they will compare two {@link org.jmock.expectation.Null Null}
|
|
35 |
* objects together, which is guaranteed to succeed.
|
|
36 |
*
|
|
37 |
* @author <a href="mailto:fbos@users.sourceforge.net">Francois Beausoleil (fbos@users.sourceforge.net)</a>
|
|
38 |
* @version $Id: Null.java,v 1.3 2002/03/28 18:16:54 custommonkey Exp $
|
|
39 |
*/
|
|
40 |
public class Null { |
|
41 |
/**
|
|
42 |
* The default description for all {@link org.jmock.expectation.Null Null}
|
|
43 |
* objects.
|
|
44 |
* This String is equal to "<code>Null</code>".
|
|
45 |
*/
|
|
46 |
public static final String DEFAULT_DESCRIPTION = "Null"; |
|
47 |
|
|
48 |
/**
|
|
49 |
* A default {@link org.jmock.expectation.Null Null} object.
|
|
50 |
* Instead of always instantiating new {@link org.jmock.expectation.Null Null}
|
|
51 |
* objects, consider using a reference to this object instead. This way,
|
|
52 |
* the virtual machine will not be taking the time required to instantiate
|
|
53 |
* an object everytime it is required.
|
|
54 |
*/
|
|
55 |
public static final Null NULL = new Null(); |
|
56 |
|
|
57 |
/** The description of this {@link org.jmock.expectation.Null Null} object. */
|
|
58 |
final private String myDescription;
|
|
59 |
|
|
60 |
/**
|
|
61 |
* Instantiates a new {@link org.jmock.expectation.Null Null} object with
|
|
62 |
* the default description.
|
|
63 |
*
|
|
64 |
* @see org.jmock.expectation.Null#DEFAULT_DESCRIPTION
|
|
65 |
*/
|
|
66 | 42 |
public Null() {
|
67 | 42 |
this(DEFAULT_DESCRIPTION);
|
68 |
} |
|
69 |
|
|
70 |
/**
|
|
71 |
* Instantiates a new {@link org.jmock.expectation.Null Null} object and
|
|
72 |
* sets it's description.
|
|
73 |
*
|
|
74 |
* @param description
|
|
75 |
*/
|
|
76 | 400 |
public Null(String description) {
|
77 | 400 |
super();
|
78 | 400 |
myDescription = description; |
79 |
} |
|
80 |
|
|
81 |
/**
|
|
82 |
* Determines equality between two objects.
|
|
83 |
* {@link org.jmock.expectation.Null Null} objects are only equal to
|
|
84 |
* another instance of themselves.
|
|
85 |
*
|
|
86 |
* @param other
|
|
87 |
*/
|
|
88 | 34 |
public boolean equals(Object other) { |
89 | 34 |
return other instanceof Null; |
90 |
} |
|
91 |
|
|
92 |
/**
|
|
93 |
* Returns this {@link org.jmock.expectation.Null Null} object's hashCode.
|
|
94 |
* All {@link org.jmock.expectation.Null Null} return the same
|
|
95 |
* hashCode value.
|
|
96 |
*/
|
|
97 | 20 |
public int hashCode() { |
98 | 20 |
return 0;
|
99 |
} |
|
100 |
|
|
101 |
/**
|
|
102 |
* Returns a string representation of this {@link org.jmock.expectation.Null Null}
|
|
103 |
* object.
|
|
104 |
* This merely returns the string passed to the constructor initially.
|
|
105 |
*/
|
|
106 | 10 |
public String toString() {
|
107 | 10 |
return myDescription;
|
108 |
} |
|
109 |
} |
|
110 |
|
|