KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > modifier > ModifierTest


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package test.modifier;
9
10 import junit.framework.TestCase;
11
12 /**
13  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
14  */

15 public class ModifierTest extends TestCase {
16     private static String JavaDoc s_logString = "";
17
18     private int privateField;
19
20     protected int protectedField;
21
22     public int publicField;
23
24     public ModifierTest() {
25     }
26
27     public ModifierTest(String JavaDoc name) {
28         super(name);
29     }
30
31     public void testPrivateMethod() {
32         s_logString = "";
33         privateMethod();
34         assertEquals("call execution invocation execution call ", s_logString);
35     }
36
37     public void testProtectedMethod() {
38         s_logString = "";
39         protectedMethod();
40         assertEquals("call execution invocation execution call ", s_logString);
41     }
42
43     public void testPublicMethod() {
44         s_logString = "";
45         publicMethod();
46         assertEquals("call execution invocation execution call ", s_logString);
47     }
48
49     public void testStaticFinalMethod() {
50         s_logString = "";
51         staticFinalMethod();
52         assertEquals("call invocation call ", s_logString);
53     }
54
55     public void testSetPublicField() {
56         s_logString = "";
57         publicField = 0;
58         assertEquals("set set ", s_logString);
59     }
60
61     public void testSetPrivateField() {
62         s_logString = "";
63         privateField = 0;
64         assertEquals("set set ", s_logString);
65     }
66
67     public void testSetProtectedField() {
68         s_logString = "";
69         protectedField = 0;
70         assertEquals("set set ", s_logString);
71     }
72
73     public void testGetPublicField() {
74         s_logString = "";
75         int i = publicField;
76         assertEquals("get get ", s_logString);
77     }
78
79     public void testGetPrivateField() {
80         s_logString = "";
81         int i = privateField;
82         assertEquals("get get ", s_logString);
83     }
84
85     public void testGetProtectedField() {
86         s_logString = "";
87         int i = protectedField;
88         assertEquals("get get ", s_logString);
89     }
90
91     public static void main(String JavaDoc[] args) {
92         junit.textui.TestRunner.run(suite());
93     }
94
95     public static junit.framework.Test suite() {
96         return new junit.framework.TestSuite(ModifierTest.class);
97     }
98
99     // ==== methods to test ====
100
public static void log(final String JavaDoc wasHere) {
101         s_logString += wasHere;
102     }
103
104     private void privateMethod() {
105         log("invocation ");
106     }
107
108     protected void protectedMethod() {
109         log("invocation ");
110     }
111
112     public void publicMethod() {
113         log("invocation ");
114     }
115
116     static final void staticFinalMethod() {
117         log("invocation ");
118     }
119 }
Popular Tags