001: package net.sf.mockcreator;
002:
003: import net.sf.mockcreator.exceptions.MockException;
004:
005: public class PrimitivesTest extends TestCase {
006: MockPrimitives mock;
007:
008: public PrimitivesTest(String name) {
009: super (name);
010: }
011:
012: public void setUp() throws Exception {
013: super .setUp();
014: mock = new MockPrimitives();
015: }
016:
017: private IllegalArgumentException th() {
018: return new IllegalArgumentException();
019: }
020:
021: public void testChar_setDummy() throws Exception {
022: mock.expectZeroOrMoreGetChar().returns('c');
023: assertEquals('c', mock.getChar(1.2));
024: assertEquals('c', mock.getChar(3.5));
025: }
026:
027: public void testChar_setDummyThrow() throws Exception {
028: mock.expectZeroOrMoreGetChar().throwable(th());
029:
030: try {
031: mock.getChar(1.2);
032: fail();
033: } catch (IllegalArgumentException ex) {
034: }
035:
036: try {
037: mock.getChar(4.2);
038: fail();
039: } catch (IllegalArgumentException ex) {
040: }
041: }
042:
043: public void testChar_expectZeroOrMoreMultiple() throws Exception {
044: mock.expectZeroOrMoreGetChar(1.2).returns('c');
045: mock.expectZeroOrMoreGetChar(1.5).returns('d');
046: mock.expectZeroOrMoreGetChar().returns('e');
047: assertEquals('d', mock.getChar(1.5));
048: assertEquals('c', mock.getChar(1.2));
049: assertEquals('e', mock.getChar(1.0));
050: assertEquals('c', mock.getChar(1.2));
051: assertEquals('d', mock.getChar(1.5));
052: }
053:
054: public void testChar_expect() throws Exception {
055: mock.expectGetChar(4.5).returns('c');
056: mock.expectGetChar(6.1).returns('d');
057: assertEquals('c', mock.getChar(4.5));
058: assertEquals('d', mock.getChar(6.1));
059: }
060:
061: public void testChar_expectThrow() throws Exception {
062: mock.expectGetChar(4.5).throwable(th());
063: mock.expectGetChar(6.1).returns('z');
064:
065: try {
066: mock.getChar(4.5);
067: fail();
068: } catch (IllegalArgumentException ex) {
069: }
070:
071: assertEquals('z', mock.getChar(6.1));
072: }
073:
074: public void testChar_accept() throws Exception {
075: mock.acceptGetChar(new Double(4.5)).returns('c');
076: mock.acceptGetChar(new Double(6.1)).returns('d');
077: assertEquals('c', mock.getChar(4.5));
078: assertEquals('d', mock.getChar(6.1));
079: }
080:
081: public void testChar_acceptThrow() throws Exception {
082: mock.acceptGetChar(new Double(4.5)).throwable(th());
083: mock.acceptGetChar(new Double(6.1)).returns('z');
084:
085: try {
086: mock.getChar(4.5);
087: fail();
088: } catch (IllegalArgumentException ex) {
089: }
090:
091: assertEquals('z', mock.getChar(6.1));
092: }
093:
094: public void testChar_UnexpectedCall() throws Exception {
095: try {
096: mock.getChar(4.5);
097: fail();
098: } catch (MockException ex) {
099: }
100: }
101:
102: public void testChar_MissedCall() throws Exception {
103: mock.expectGetChar(6.1).returns('z');
104:
105: try {
106: MockCore.verify();
107: fail();
108: } catch (MockException ex) {
109: }
110: }
111:
112: public void testChar_InBlock() throws Exception {
113: MockCore.startBlock();
114: mock.expectGetChar(4.5).returns('c');
115: mock.expectGetChar(6.1).returns('d');
116: MockCore.endBlock();
117: assertEquals('d', mock.getChar(6.1));
118: assertEquals('c', mock.getChar(4.5));
119: }
120:
121: public void testShort_setDummy() throws Exception {
122: mock.expectZeroOrMoreGetShort().returns((short) 123);
123: assertEquals(123, mock.getShort((float) 1.2));
124: assertEquals(123, mock.getShort((float) 3.5));
125: }
126:
127: public void testShort_setDummyThrow() throws Exception {
128: mock.expectZeroOrMoreGetShort().throwable(th());
129:
130: try {
131: mock.getShort(1.2f);
132: fail();
133: } catch (IllegalArgumentException ex) {
134: }
135:
136: try {
137: mock.getShort(4.2f);
138: fail();
139: } catch (IllegalArgumentException ex) {
140: }
141: }
142:
143: public void testShort_expectZeroOrMoreMultiple() throws Exception {
144: mock.expectZeroOrMoreGetShort(1.2f).returns((short) 123);
145: mock.expectZeroOrMoreGetShort(1.5f).returns((short) 456);
146: mock.expectZeroOrMoreGetShort().returns((short) 789);
147: assertEquals(456, mock.getShort(1.5f));
148: assertEquals(123, mock.getShort(1.2f));
149: assertEquals(789, mock.getShort(1.0f));
150: assertEquals(123, mock.getShort(1.2f));
151: assertEquals(456, mock.getShort(1.5f));
152: }
153:
154: public void testShort_expect() throws Exception {
155: mock.expectGetShort(4.5f).returns((short) 123);
156: mock.expectGetShort(6.1f).returns((short) 456);
157: assertEquals(123, mock.getShort(4.5f));
158: assertEquals(456, mock.getShort(6.1f));
159: }
160:
161: public void testShort_expectThrow() throws Exception {
162: mock.expectGetShort(4.5f).throwable(th());
163: mock.expectGetShort(6.1f).returns((short) 123);
164:
165: try {
166: mock.getShort(4.5f);
167: fail();
168: } catch (IllegalArgumentException ex) {
169: }
170:
171: assertEquals(123, mock.getShort(6.1f));
172: }
173:
174: public void testShort_accept() throws Exception {
175: mock.acceptGetShort(new Float(4.5)).returns((short) 123);
176: mock.acceptGetShort(new Float(6.1)).returns((short) 456);
177: assertEquals(123, mock.getShort(4.5f));
178: assertEquals(456, mock.getShort(6.1f));
179: }
180:
181: public void testShort_acceptThrow() throws Exception {
182: mock.acceptGetShort(new Float(4.5)).throwable(th());
183: mock.acceptGetShort(new Float(6.1)).returns((short) 123);
184:
185: try {
186: mock.getShort(4.5f);
187: fail();
188: } catch (IllegalArgumentException ex) {
189: }
190:
191: assertEquals(123, mock.getShort(6.1f));
192: }
193:
194: public void testShort_UnexpectedCall() throws Exception {
195: try {
196: mock.getShort(4.5f);
197: fail();
198: } catch (MockException ex) {
199: }
200: }
201:
202: public void testShort_MissedCall() throws Exception {
203: mock.expectGetShort(6.1f).returns((short) 123);
204:
205: try {
206: MockCore.verify();
207: fail();
208: } catch (MockException ex) {
209: }
210: }
211:
212: public void testShort_InBlock() throws Exception {
213: MockCore.startBlock();
214: mock.expectGetShort(4.5f).returns((short) 123);
215: mock.expectGetShort(6.1f).returns((short) 456);
216: MockCore.endBlock();
217: assertEquals(456, mock.getShort(6.1f));
218: assertEquals(123, mock.getShort(4.5f));
219: }
220:
221: public void testByte_setDummy() throws Exception {
222: mock.expectZeroOrMoreGetByte().returns((byte) 123);
223: assertEquals(123, mock.getByte(true));
224: assertEquals(123, mock.getByte(false));
225: }
226:
227: public void testByte_setDummyThrow() throws Exception {
228: mock.expectZeroOrMoreGetByte().throwable(th());
229:
230: try {
231: mock.getByte(true);
232: fail();
233: } catch (IllegalArgumentException ex) {
234: }
235:
236: try {
237: mock.getByte(false);
238: fail();
239: } catch (IllegalArgumentException ex) {
240: }
241: }
242:
243: public void testByte_expectZeroOrMoreMultiple() throws Exception {
244: mock.expectZeroOrMoreGetByte(true).returns((byte) 12);
245: mock.expectZeroOrMoreGetByte(false).returns((byte) 34);
246: mock.expectZeroOrMoreGetByte().returns((byte) 56);
247: assertEquals(12, mock.getByte(true));
248: assertEquals(34, mock.getByte(false));
249: assertEquals(34, mock.getByte(false));
250: assertEquals(12, mock.getByte(true));
251: }
252:
253: public void testByte_expect() throws Exception {
254: mock.expectGetByte(true).returns((byte) 1);
255: mock.expectGetByte(false).returns((byte) 2);
256: assertEquals(1, mock.getByte(true));
257: assertEquals(2, mock.getByte(false));
258: }
259:
260: public void testByte_expectThrow() throws Exception {
261: mock.expectGetByte(true).throwable(th());
262: mock.expectGetByte(false).returns((byte) 1);
263:
264: try {
265: mock.getByte(true);
266: fail();
267: } catch (IllegalArgumentException ex) {
268: }
269:
270: assertEquals(1, mock.getByte(false));
271: }
272:
273: public void testByte_accept() throws Exception {
274: mock.acceptGetByte(new Boolean(true)).returns((byte) 1);
275: mock.acceptGetByte(new Boolean(false)).returns((byte) 2);
276: assertEquals(1, mock.getByte(true));
277: assertEquals(2, mock.getByte(false));
278: }
279:
280: public void testByte_acceptThrow() throws Exception {
281: mock.acceptGetByte(new Boolean(true)).throwable(th());
282: mock.acceptGetByte(new Boolean(false)).returns((byte) 1);
283:
284: try {
285: mock.getByte(true);
286: fail();
287: } catch (IllegalArgumentException ex) {
288: }
289:
290: assertEquals(1, mock.getByte(false));
291: }
292:
293: public void testByte_UnexpectedCall() throws Exception {
294: try {
295: mock.getByte(false);
296: fail();
297: } catch (MockException ex) {
298: }
299: }
300:
301: public void testByte_MissedCall() throws Exception {
302: mock.expectGetByte(false).returns((byte) 5);
303:
304: try {
305: MockCore.verify();
306: fail();
307: } catch (MockException ex) {
308: }
309: }
310:
311: public void testByte_InBlock() throws Exception {
312: MockCore.startBlock();
313: mock.expectGetByte(true).returns((byte) 1);
314: mock.expectGetByte(false).returns((byte) 2);
315: MockCore.endBlock();
316: assertEquals(2, mock.getByte(false));
317: assertEquals(1, mock.getByte(true));
318: }
319:
320: public void testInt_setDummy() throws Exception {
321: mock.expectZeroOrMoreGetInt().returns(123);
322: assertEquals(123, mock.getInt(12));
323: assertEquals(123, mock.getInt(35));
324: }
325:
326: public void testInt_setDummyThrow() throws Exception {
327: mock.expectZeroOrMoreGetInt().throwable(th());
328:
329: try {
330: mock.getInt(12);
331: fail();
332: } catch (IllegalArgumentException ex) {
333: }
334:
335: try {
336: mock.getInt(42);
337: fail();
338: } catch (IllegalArgumentException ex) {
339: }
340: }
341:
342: public void testInt_expectZeroOrMoreMultiple() throws Exception {
343: mock.expectZeroOrMoreGetInt(12).returns(123);
344: mock.expectZeroOrMoreGetInt(15).returns(456);
345: mock.expectZeroOrMoreGetInt().returns(789);
346: assertEquals(456, mock.getInt(15));
347: assertEquals(123, mock.getInt(12));
348: assertEquals(789, mock.getInt(10));
349: assertEquals(123, mock.getInt(12));
350: assertEquals(456, mock.getInt(15));
351: }
352:
353: public void testInt_expect() throws Exception {
354: mock.expectGetInt(45).returns(123);
355: mock.expectGetInt(61).returns(456);
356: assertEquals(123, mock.getInt(45));
357: assertEquals(456, mock.getInt(61));
358: }
359:
360: public void testInt_expectThrow() throws Exception {
361: mock.expectGetInt(45).throwable(th());
362: mock.expectGetInt(61).returns(123);
363:
364: try {
365: mock.getInt(45);
366: fail();
367: } catch (IllegalArgumentException ex) {
368: }
369:
370: assertEquals(123, mock.getInt(61));
371: }
372:
373: public void testInt_accept() throws Exception {
374: mock.acceptGetInt(new Long(45)).returns(123);
375: mock.acceptGetInt(new Long(61)).returns(456);
376: assertEquals(123, mock.getInt(45));
377: assertEquals(456, mock.getInt(61));
378: }
379:
380: public void testInt_acceptThrow() throws Exception {
381: mock.acceptGetInt(new Long(45)).throwable(th());
382: mock.acceptGetInt(new Long(61)).returns(123);
383:
384: try {
385: mock.getInt(45);
386: fail();
387: } catch (IllegalArgumentException ex) {
388: }
389:
390: assertEquals(123, mock.getInt(61));
391: }
392:
393: public void testInt_UnexpectedCall() throws Exception {
394: try {
395: mock.getInt(45);
396: fail();
397: } catch (MockException ex) {
398: }
399: }
400:
401: public void testInt_MissedCall() throws Exception {
402: mock.expectGetInt(33).returns(5);
403:
404: try {
405: MockCore.verify();
406: fail();
407: } catch (MockException ex) {
408: }
409: }
410:
411: public void testInt_InBlock() throws Exception {
412: MockCore.startBlock();
413: mock.expectGetInt(45).returns(123);
414: mock.expectGetInt(61).returns(456);
415: MockCore.endBlock();
416: assertEquals(456, mock.getInt(61));
417: assertEquals(123, mock.getInt(45));
418: }
419:
420: public void testLong_setDummy() throws Exception {
421: mock.expectZeroOrMoreGetLong().returns(123);
422: assertEquals(123, mock.getLong(12));
423: assertEquals(123, mock.getLong(35));
424: }
425:
426: public void testLong_setDummyThrow() throws Exception {
427: mock.expectZeroOrMoreGetLong().throwable(th());
428:
429: try {
430: mock.getLong(12);
431: fail();
432: } catch (IllegalArgumentException ex) {
433: }
434:
435: try {
436: mock.getLong(42);
437: fail();
438: } catch (IllegalArgumentException ex) {
439: }
440: }
441:
442: public void testLong_expectZeroOrMoreMultiple() throws Exception {
443: mock.expectZeroOrMoreGetLong(12).returns(123);
444: mock.expectZeroOrMoreGetLong(15).returns(456);
445: mock.expectZeroOrMoreGetLong().returns(789);
446: assertEquals(456, mock.getLong(15));
447: assertEquals(123, mock.getLong(12));
448: assertEquals(789, mock.getLong(10));
449: assertEquals(123, mock.getLong(12));
450: assertEquals(456, mock.getLong(15));
451: }
452:
453: public void testLong_expect() throws Exception {
454: mock.expectGetLong(45).returns(123);
455: mock.expectGetLong(61).returns(456);
456: assertEquals(123, mock.getLong(45));
457: assertEquals(456, mock.getLong(61));
458: }
459:
460: public void testLong_expectThrow() throws Exception {
461: mock.expectGetLong(45).throwable(th());
462: mock.expectGetLong(61).returns(123);
463:
464: try {
465: mock.getLong(45);
466: fail();
467: } catch (IllegalArgumentException ex) {
468: }
469:
470: assertEquals(123, mock.getLong(61));
471: }
472:
473: public void testLong_accept() throws Exception {
474: mock.acceptGetLong(new Integer(45)).returns(123);
475: mock.acceptGetLong(new Integer(61)).returns(456);
476: assertEquals(123, mock.getLong(45));
477: assertEquals(456, mock.getLong(61));
478: }
479:
480: public void testLong_acceptThrow() throws Exception {
481: mock.acceptGetLong(new Integer(45)).throwable(th());
482: mock.acceptGetLong(new Integer(61)).returns(123);
483:
484: try {
485: mock.getLong(45);
486: fail();
487: } catch (IllegalArgumentException ex) {
488: }
489:
490: assertEquals(123, mock.getLong(61));
491: }
492:
493: public void testLong_UnexpectedCall() throws Exception {
494: try {
495: mock.getLong(45);
496: fail();
497: } catch (MockException ex) {
498: }
499: }
500:
501: public void testLong_MissedCall() throws Exception {
502: mock.expectGetLong(17).returns(5L);
503:
504: try {
505: MockCore.verify();
506: fail();
507: } catch (MockException ex) {
508: }
509: }
510:
511: public void testLong_InBlock() throws Exception {
512: MockCore.startBlock();
513: mock.expectGetLong(45).returns(123);
514: mock.expectGetLong(61).returns(456);
515: MockCore.endBlock();
516: assertEquals(456, mock.getLong(61));
517: assertEquals(123, mock.getLong(45));
518: }
519:
520: public void testFloat_setDummy() throws Exception {
521: mock.expectZeroOrMoreGetFloat().returns(123.4f);
522: assertEquals(123.4f, mock.getFloat((short) 12), 0.1f);
523: assertEquals(123.4f, mock.getFloat((short) 35), 0.1f);
524: }
525:
526: public void testFloat_setDummyThrow() throws Exception {
527: mock.expectZeroOrMoreGetFloat().throwable(th());
528:
529: try {
530: mock.getFloat((short) 12);
531: fail();
532: } catch (IllegalArgumentException ex) {
533: }
534:
535: try {
536: mock.getFloat((short) 42);
537: fail();
538: } catch (IllegalArgumentException ex) {
539: }
540: }
541:
542: public void testFloat_expectZeroOrMoreMultiple() throws Exception {
543: mock.expectZeroOrMoreGetFloat((short) 12).returns(123.4f);
544: mock.expectZeroOrMoreGetFloat((short) 15).returns(456f);
545: mock.expectZeroOrMoreGetFloat().returns((short) 789);
546: assertEquals(456f, mock.getFloat((short) 15), 0.1f);
547: assertEquals(123.4f, mock.getFloat((short) 12), 0.1f);
548: assertEquals(789f, mock.getFloat((short) 10), 0.1f);
549: assertEquals(123.4f, mock.getFloat((short) 12), 0.1f);
550: assertEquals(456f, mock.getFloat((short) 15), 0.1f);
551: }
552:
553: public void testFloat_expect() throws Exception {
554: mock.expectGetFloat((short) 45).returns(123.4f);
555: mock.expectGetFloat((short) 61).returns(456f);
556: assertEquals(123.4f, mock.getFloat((short) 45), 0.1f);
557: assertEquals(456f, mock.getFloat((short) 61), 0.1f);
558: }
559:
560: public void testFloat_expectThrow() throws Exception {
561: mock.expectGetFloat((short) 45).throwable(th());
562: mock.expectGetFloat((short) 61).returns(123.4f);
563:
564: try {
565: mock.getFloat((short) 45);
566: fail();
567: } catch (IllegalArgumentException ex) {
568: }
569:
570: assertEquals(123.4f, mock.getFloat((short) 61), 0.1f);
571: }
572:
573: public void testFloat_accept() throws Exception {
574: mock.acceptGetFloat(new Short((short) 45)).returns(123.4f);
575: mock.acceptGetFloat(new Short((short) 61)).returns(456f);
576: assertEquals(123.4f, mock.getFloat((short) 45), 0.1f);
577: assertEquals(456f, mock.getFloat((short) 61), 0.1f);
578: }
579:
580: public void testFloat_acceptThrow() throws Exception {
581: mock.acceptGetFloat(new Short((short) 45)).throwable(th());
582: mock.acceptGetFloat(new Short((short) 61)).returns(123.4f);
583:
584: try {
585: mock.getFloat((short) 45);
586: fail();
587: } catch (IllegalArgumentException ex) {
588: }
589:
590: assertEquals(123.4f, mock.getFloat((short) 61), 0.1f);
591: }
592:
593: public void testFloat_UnexpectedCall() throws Exception {
594: try {
595: mock.getFloat((short) 45);
596: fail();
597: } catch (MockException ex) {
598: }
599: }
600:
601: public void testFloat_MissedCall() throws Exception {
602: mock.expectGetFloat((short) 17).returns(5.3f);
603:
604: try {
605: MockCore.verify();
606: fail();
607: } catch (MockException ex) {
608: }
609: }
610:
611: public void testFloat_InBlock() throws Exception {
612: MockCore.startBlock();
613: mock.expectGetFloat((short) 45).returns(123.4f);
614: mock.expectGetFloat((short) 61).returns(456f);
615: MockCore.endBlock();
616: assertEquals(456f, mock.getFloat((short) 61), 0.1f);
617: assertEquals(123.4f, mock.getFloat((short) 45), 0.1f);
618: }
619:
620: public void testDouble_setDummy() throws Exception {
621: mock.expectZeroOrMoreGetDouble().returns(123.4f);
622: assertEquals(123.4f, mock.getDouble((char) 12), 0.1f);
623: assertEquals(123.4f, mock.getDouble((char) 35), 0.1f);
624: }
625:
626: public void testDouble_setDummyThrow() throws Exception {
627: mock.expectZeroOrMoreGetDouble().throwable(th());
628:
629: try {
630: mock.getDouble((char) 12);
631: fail();
632: } catch (IllegalArgumentException ex) {
633: }
634:
635: try {
636: mock.getDouble((char) 42);
637: fail();
638: } catch (IllegalArgumentException ex) {
639: }
640: }
641:
642: public void testDouble_expectZeroOrMoreMultiple() throws Exception {
643: mock.expectZeroOrMoreGetDouble((char) 12).returns(123.4f);
644: mock.expectZeroOrMoreGetDouble((char) 15).returns(456f);
645: mock.expectZeroOrMoreGetDouble().returns((char) 789);
646: assertEquals(456f, mock.getDouble((char) 15), 0.1f);
647: assertEquals(123.4f, mock.getDouble((char) 12), 0.1f);
648: assertEquals(789f, mock.getDouble((char) 10), 0.1f);
649: assertEquals(123.4f, mock.getDouble((char) 12), 0.1f);
650: assertEquals(456f, mock.getDouble((char) 15), 0.1f);
651: }
652:
653: public void testDouble_expect() throws Exception {
654: mock.expectGetDouble((char) 45).returns(123.4f);
655: mock.expectGetDouble((char) 61).returns(456f);
656: assertEquals(123.4f, mock.getDouble((char) 45), 0.1f);
657: assertEquals(456f, mock.getDouble((char) 61), 0.1f);
658: }
659:
660: public void testDouble_expectThrow() throws Exception {
661: mock.expectGetDouble((char) 45).throwable(th());
662: mock.expectGetDouble((char) 61).returns(123.4f);
663:
664: try {
665: mock.getDouble((char) 45);
666: fail();
667: } catch (IllegalArgumentException ex) {
668: }
669:
670: assertEquals(123.4f, mock.getDouble((char) 61), 0.1f);
671: }
672:
673: public void testDouble_accept() throws Exception {
674: mock.acceptGetDouble(new Character((char) 45)).returns(123.4f);
675: mock.acceptGetDouble(new Character((char) 61)).returns(456f);
676: assertEquals(123.4f, mock.getDouble((char) 45), 0.1f);
677: assertEquals(456f, mock.getDouble((char) 61), 0.1f);
678: }
679:
680: public void testDouble_acceptThrow() throws Exception {
681: mock.acceptGetDouble(new Character((char) 45)).throwable(th());
682: mock.acceptGetDouble(new Character((char) 61)).returns(123.4f);
683:
684: try {
685: mock.getDouble((char) 45);
686: fail();
687: } catch (IllegalArgumentException ex) {
688: }
689:
690: assertEquals(123.4f, mock.getDouble((char) 61), 0.1f);
691: }
692:
693: public void testDouble_UnexpectedCall() throws Exception {
694: try {
695: mock.getDouble((char) 45);
696: fail();
697: } catch (MockException ex) {
698: }
699: }
700:
701: public void testDouble_MissedCall() throws Exception {
702: mock.expectGetDouble((char) 17).returns(5.7);
703:
704: try {
705: MockCore.verify();
706: fail();
707: } catch (MockException ex) {
708: }
709: }
710:
711: public void testDouble_InBlock() throws Exception {
712: MockCore.startBlock();
713: mock.expectGetDouble((char) 45).returns(123.4f);
714: mock.expectGetDouble((char) 61).returns(456f);
715: MockCore.endBlock();
716: assertEquals(456f, mock.getDouble((char) 61), 0.1f);
717: assertEquals(123.4f, mock.getDouble((char) 45), 0.1f);
718: }
719:
720: public void testBoolean_setDummy() throws Exception {
721: mock.expectZeroOrMoreGetBoolean().returns(true);
722: assertEquals(true, mock.getBoolean((byte) 12));
723: assertEquals(true, mock.getBoolean((byte) 35));
724: }
725:
726: public void testBoolean_setDummyThrow() throws Exception {
727: mock.expectZeroOrMoreGetBoolean().throwable(th());
728:
729: try {
730: mock.getBoolean((byte) 12);
731: fail();
732: } catch (IllegalArgumentException ex) {
733: }
734:
735: try {
736: mock.getBoolean((byte) 42);
737: fail();
738: } catch (IllegalArgumentException ex) {
739: }
740: }
741:
742: public void testBoolean_expectZeroOrMoreMultiple() throws Exception {
743: mock.expectZeroOrMoreGetBoolean((byte) 12).returns(true);
744: mock.expectZeroOrMoreGetBoolean().returns(false);
745: assertEquals(true, mock.getBoolean((byte) 12));
746: assertEquals(false, mock.getBoolean((byte) 10));
747: assertEquals(true, mock.getBoolean((byte) 12));
748: }
749:
750: public void testBoolean_expect() throws Exception {
751: mock.expectGetBoolean((byte) 45).returns(true);
752: mock.expectGetBoolean((byte) 61).returns(false);
753: assertEquals(true, mock.getBoolean((byte) 45));
754: assertEquals(false, mock.getBoolean((byte) 61));
755: }
756:
757: public void testBoolean_expectThrow() throws Exception {
758: mock.expectGetBoolean((byte) 45).throwable(th());
759: mock.expectGetBoolean((byte) 61).returns(true);
760:
761: try {
762: mock.getBoolean((byte) 45);
763: fail();
764: } catch (IllegalArgumentException ex) {
765: }
766:
767: assertEquals(true, mock.getBoolean((byte) 61));
768: }
769:
770: public void testBoolean_accept() throws Exception {
771: mock.acceptGetBoolean(new Byte((byte) 45)).returns(true);
772: mock.acceptGetBoolean(new Byte((byte) 61)).returns(false);
773: assertEquals(true, mock.getBoolean((byte) 45));
774: assertEquals(false, mock.getBoolean((byte) 61));
775: }
776:
777: public void testBoolean_acceptThrow() throws Exception {
778: mock.acceptGetBoolean(new Byte((byte) 45)).throwable(th());
779: mock.acceptGetBoolean(new Byte((byte) 61)).returns(false);
780:
781: try {
782: mock.getBoolean((byte) 45);
783: fail();
784: } catch (IllegalArgumentException ex) {
785: }
786:
787: assertEquals(false, mock.getBoolean((byte) 61));
788: }
789:
790: public void testBoolean_UnexpectedCall() throws Exception {
791: try {
792: mock.getBoolean((byte) 45);
793: fail();
794: } catch (MockException ex) {
795: }
796: }
797:
798: public void testBoolean_MissedCall() throws Exception {
799: mock.expectGetBoolean((byte) 17).returns(false);
800:
801: try {
802: MockCore.verify();
803: fail();
804: } catch (MockException ex) {
805: }
806: }
807:
808: public void testBoolean_InBlock() throws Exception {
809: MockCore.startBlock();
810: mock.expectGetBoolean((byte) 45).returns(true);
811: mock.expectGetBoolean((byte) 61).returns(false);
812: MockCore.endBlock();
813: assertEquals(false, mock.getBoolean((byte) 61));
814: assertEquals(true, mock.getBoolean((byte) 45));
815: }
816:
817: public void testPrimitiveAndNot_accept() throws Exception {
818: mock.expectFoo(new Integer(5));
819:
820: try {
821: mock.foo(5);
822: fail();
823: } catch (MockException ex) {
824: }
825: }
826: }
|