01: package org.hanseltest;
02:
03: /**
04: * Switch statements to be covered by the testcases.
05: * @author Niklas Mehner
06: */
07: public class CoverSwitch {
08:
09: /**
10: * Simple switch.
11: * @param i Switch parameter.
12: * @return 1 if i=0, 2 if i=1, 3 if i=5, 4 otherwise.
13: */
14: public int coverSimpleSwitch(int i) {
15: switch (i) {
16: case 0:
17: return 1;
18: case 1:
19: return 2;
20: case 5:
21: return 3;
22: default:
23: return 4;
24: }
25: }
26:
27: /**
28: * Switch without default.
29: * @param i Switch parameter.
30: * @return 2, or 3 if i=0.
31: */
32: public int coverNoDefault(int i) {
33: int result = 2;
34:
35: switch (i) {
36: case 0:
37: result++;
38: }
39:
40: return result;
41: }
42:
43: /**
44: * Switch translated to a tableswitch.
45: * @param i Switch parameter.
46: * @return 1 if i in [1..3], 2 if i in [4..6], 3 else.
47: */
48: public int coverSimpleSwitch2(int i) {
49: int result;
50:
51: switch (i) {
52: case 1:
53: case 2:
54: case 3:
55: result = 1;
56: break;
57: case 4:
58: case 5:
59: case 6:
60: result = 2;
61: break;
62: default:
63: result = 3;
64: }
65:
66: return result;
67: }
68: }
|