KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hanseltest > CoverIf


1 package org.hanseltest;
2
3 /**
4  * Class containing all kinds of different uses of if-statements.
5  *
6  * @author Niklas Mehner
7  */

8 public class CoverIf {
9
10     /**
11      * Method contains a simple if statement.
12      * @param condition Condition.
13      * @return 0 if condition is false, 1 otherwise.
14      */

15     public int simpleIf(boolean condition) {
16         int result = 0;
17
18         if (condition) {
19             result++;
20         }
21
22         return result;
23     }
24
25     /**
26      * Method contains a simple if-else.
27      * @param condition condition for the if statement.
28      * @return 3 if condition is false, 4 otherwise.
29      */

30     public int ifElse(boolean condition) {
31         if (condition) {
32             return 3;
33         } else {
34             return 4;
35         }
36     }
37
38     /**
39      * Compare to references.
40      * @param obj1 Reference one.
41      * @param obj2 Reference two.
42      * @return 0 if (obj1 == obj2), 1 otherwise.
43      */

44     public int ifPointer(Object JavaDoc obj1, Object JavaDoc obj2) {
45         if (obj1 == obj2) {
46             return 0;
47         } else {
48             return 1;
49         }
50     }
51
52     /**
53      * Method contains a nested if statement.
54      * @param conditionA First Condition.
55      * @param conditionB Second Condition.
56      * @return Value depending on conditions (1..4);
57      */

58     public int nestedIf(boolean conditionA, boolean conditionB) {
59         if (conditionA) {
60             if (conditionB) {
61                 return 1;
62             } else {
63                 return 2;
64             }
65         } else {
66             if (conditionB) {
67                 return 3;
68             } else {
69                 return 4;
70             }
71         }
72     }
73 }
74
Popular Tags