001: package net.sf.mockcreator;
002:
003: import java.util.*;
004:
005: import net.sf.mockcreator.Java15.Java15Enum;
006: import net.sf.mockcreator.exceptions.MockException;
007: import net.sf.mockcreator.expectable.Ignore;
008:
009: public class Java15Test extends TestCase {
010: MockJava15 mock;
011:
012: public void testExpect() throws Exception {
013: MockCore.reset();
014: mock = new MockJava15();
015: mock.expectGetNames().returns(new HashSet<String>());
016: mock.getNames();
017: MockCore.verify();
018: }
019:
020: public void DISABLED_TEMPORARELY_testExpectWrongGenericsParameter()
021: throws Exception {
022: Set ints = new HashSet<Integer>();
023: MockCore.reset();
024: mock = new MockJava15();
025: mock.acceptSetNames(new HashSet<String>());
026:
027: try {
028: mock.setNames(ints);
029: fail();
030: } catch (MockException ex) {
031: }
032:
033: MockCore.verify();
034: }
035:
036: public void testExpectWrongGenericsParameter2() throws Exception {
037: Set ints = new HashSet<Integer>();
038: ints.add(new Integer(1));
039:
040: Set strings = new HashSet<String>();
041: strings.add("foo");
042:
043: MockCore.reset();
044: mock = new MockJava15();
045: mock.acceptSetNames(strings);
046:
047: try {
048: mock.setNames(ints);
049: fail();
050: } catch (net.sf.mockcreator.exceptions.MockException ex) {
051: }
052:
053: MockCore.reset();
054: }
055:
056: public void testExpectZeroOrMore() throws Exception {
057: MockCore.reset();
058: mock = new MockJava15();
059: mock.expectZeroOrMoreGetNames().returns(new HashSet<String>());
060: mock.getNames();
061: mock.getNames();
062: mock.getNames();
063: MockCore.verify();
064: }
065:
066: public void testAccept() throws Exception {
067: MockCore.reset();
068: mock = new MockJava15();
069: mock.acceptSetNames(new HashSet<String>());
070: mock.setNames(new HashSet<String>());
071: MockCore.verify();
072: }
073:
074: public void testThrowable() throws Exception {
075: MockCore.reset();
076: mock = new MockJava15();
077: mock.expectGetNames().throwable(new IllegalArgumentException());
078: try {
079: mock.getNames();
080: } catch (IllegalArgumentException ex) {
081: }
082: MockCore.verify();
083: }
084:
085: // public Set<? extends List> mess1(Object ... args);
086:
087: public void testExpectVariableParams() throws Exception {
088: Set<ArrayList> ret = new HashSet<ArrayList>();
089:
090: MockCore.reset();
091: mock = new MockJava15();
092: mock.expectMess1("vasya", "petya").returns(ret);
093:
094: Set real = mock.mess1("vasya", "petya");
095: assertEquals(ret, real);
096:
097: MockCore.verify();
098: }
099:
100: public void testExpectZeroOrMoreVariableParams() throws Exception {
101: Set<ArrayList> ret = new HashSet<ArrayList>();
102:
103: MockCore.reset();
104: mock = new MockJava15();
105: mock.expectZeroOrMoreMess1("vasya", "petya").returns(ret);
106: mock.expectZeroOrMoreMess1().returns(null);
107:
108: Set real = mock.mess1("vasya", "petya");
109: assertEquals(ret, real);
110:
111: assertNull(mock.mess1("foo"));
112:
113: real = mock.mess1("vasya", "petya");
114: assertEquals(ret, real);
115:
116: MockCore.verify();
117: }
118:
119: public void testExpectVariableParamsFails() throws Exception {
120: Set<ArrayList> ret = new HashSet<ArrayList>();
121:
122: MockCore.reset();
123: mock = new MockJava15();
124: mock.expectMess1("vasya", "petya").returns(ret);
125:
126: try {
127: mock.mess1(123);
128: fail();
129: } catch (MockException ex) {
130: }
131: }
132:
133: public void testAcceptVariableParams() throws Exception {
134: Set<ArrayList> ret = new HashSet<ArrayList>();
135:
136: MockCore.reset();
137: mock = new MockJava15();
138: mock.acceptMess1("vasya", new Ignore()).returns(ret);
139:
140: Set real = mock.mess1("vasya", "masha");
141: assertEquals(ret, real);
142:
143: MockCore.verify();
144: }
145:
146: public void testAcceptVariableParamsFails() throws Exception {
147: Set<ArrayList> ret = new HashSet<ArrayList>();
148:
149: MockCore.reset();
150: mock = new MockJava15();
151: mock.acceptMess1("vasya", "petya").returns(ret);
152:
153: try {
154: mock.mess1(123);
155: fail();
156: } catch (MockException ex) {
157: }
158: }
159:
160: // public void enums(Java15Enum e);
161:
162: public void testExpectEnum() throws Exception {
163: MockCore.reset();
164: mock = new MockJava15();
165: mock.expectEnums(Java15Enum.FOO).returns(5);
166:
167: int ret = mock.enums(Java15Enum.FOO);
168: assertEquals(5, ret);
169:
170: MockCore.verify();
171: }
172:
173: public void testExpectFailed() throws Exception {
174: MockCore.reset();
175: mock = new MockJava15();
176: mock.expectEnums(Java15Enum.FOO).returns(5);
177:
178: try {
179: mock.enums(Java15Enum.BAR);
180: fail();
181: } catch (MockException ex) {
182: }
183:
184: MockCore.reset();
185: }
186:
187: public void testExpectZeroOrMoreEnum() throws Exception {
188: MockCore.reset();
189: mock = new MockJava15();
190: mock.expectZeroOrMoreEnums(Java15Enum.FOO).returns(5);
191: mock.expectZeroOrMoreEnums().returns(333);
192:
193: assertEquals(5, mock.enums(Java15Enum.FOO));
194: assertEquals(5, mock.enums(Java15Enum.FOO));
195: assertEquals(333, mock.enums(Java15Enum.BAR));
196: assertEquals(333, mock.enums(null));
197: assertEquals(5, mock.enums(Java15Enum.FOO));
198:
199: MockCore.verify();
200: }
201:
202: public void testAcceotEnum() throws Exception {
203: MockCore.reset();
204: mock = new MockJava15();
205: mock.acceptEnums(new Ignore()).returns(5);
206:
207: int ret = mock.enums(Java15Enum.BAZ);
208: assertEquals(5, ret);
209:
210: MockCore.verify();
211: }
212:
213: public void testAcceptFailed() throws Exception {
214: MockCore.reset();
215: mock = new MockJava15();
216: mock.acceptEnums(Java15Enum.FOO).returns(5);
217:
218: try {
219: mock.enums(Java15Enum.BAR);
220: fail();
221: } catch (MockException ex) {
222: }
223:
224: MockCore.reset();
225: }
226: }
|