001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package test.annotation;
008:
009: import junit.framework.TestCase;
010: import org.codehaus.aspectwerkz.annotation.Annotations;
011:
012: import java.lang.reflect.Method;
013:
014: /**
015: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
016: */
017: public class AnnotationTest extends TestCase {
018: private static String s_logString = "";
019:
020: /**
021: * @AnnotationPrivateField
022: */
023: private int privateField;
024:
025: /**
026: * @AnnotationProtectedField
027: */
028: protected int protectedField;
029:
030: /**
031: * @AnnotationPublicField
032: */
033: public int publicField;
034:
035: /**
036: * @AnnotationPackagePrivateField
037: */
038: int packagePrivateField;
039:
040: public AnnotationTest() {
041: }
042:
043: public AnnotationTest(String name) {
044: super (name);
045: }
046:
047: public void testPrivateMethod() {
048: s_logString = "";
049: privateMethod();
050: assertEquals("call execution invocation execution call ",
051: s_logString);
052: }
053:
054: public void testProtectedMethod() {
055: s_logString = "";
056: protectedMethod();
057: assertEquals("call execution invocation execution call ",
058: s_logString);
059: }
060:
061: public void testPackagePrivateMethod() {
062: s_logString = "";
063: packagePrivateMethod();
064: assertEquals("call execution invocation execution call ",
065: s_logString);
066: }
067:
068: public void testPublicMethod() {
069: s_logString = "";
070: publicMethod();
071: assertEquals(
072: "call execution execution2 invocation execution2 execution call ",
073: s_logString);
074: }
075:
076: public void testSetPublicField() {
077: s_logString = "";
078: publicField = 0;
079: assertEquals("set set ", s_logString);
080: }
081:
082: public void testSetPrivateField() {
083: s_logString = "";
084: privateField = 0;
085: assertEquals("set set ", s_logString);
086: }
087:
088: public void testSetProtectedField() {
089: s_logString = "";
090: protectedField = 0;
091: assertEquals("set set ", s_logString);
092: }
093:
094: public void testSetPackagePrivateField() {
095: s_logString = "";
096: packagePrivateField = 0;
097: assertEquals("set set ", s_logString);
098: }
099:
100: public void testGetPublicField() {
101: s_logString = "";
102: int i = publicField;
103: assertEquals("get get ", s_logString);
104: }
105:
106: public void testGetPrivateField() {
107: s_logString = "";
108: int i = privateField;
109: assertEquals("get get ", s_logString);
110: }
111:
112: public void testGetProtectedField() {
113: s_logString = "";
114: int i = protectedField;
115: assertEquals("get get ", s_logString);
116: }
117:
118: public void testGetPackagePrivateField() {
119: s_logString = "";
120: int i = packagePrivateField;
121: assertEquals("get get ", s_logString);
122: }
123:
124: public void testBootstrapCLClassAnnotation() throws Throwable {
125: Method concat = String.class.getMethod("concat",
126: new Class[] { String.class });
127: try {
128: Annotations.getAnnotation("foo", String.class);
129: Annotations.getAnnotation("foo", concat);
130: } catch (Throwable t) {
131: fail(t.toString());
132: }
133: }
134:
135: //-------
136:
137: public static void main(String[] args) {
138: junit.textui.TestRunner.run(suite());
139: }
140:
141: public static junit.framework.Test suite() {
142: return new junit.framework.TestSuite(AnnotationTest.class);
143: }
144:
145: // ==== methods to test ====
146: public static void log(final String wasHere) {
147: s_logString += wasHere;
148: }
149:
150: /**
151: * @AnnotationPrivateMethod
152: */
153: private void privateMethod() {
154: log("invocation ");
155: }
156:
157: /**
158: * @AnnotationProtectedMethod
159: */
160: protected void protectedMethod() {
161: log("invocation ");
162: }
163:
164: /**
165: * @AnnotationPublicMethod
166: * @AnnotationPublicMethod2
167: */
168: public void publicMethod() {
169: log("invocation ");
170: }
171:
172: /**
173: * @AnnotationPackagePrivateMethod
174: */
175: void packagePrivateMethod() {
176: log("invocation ");
177: }
178: }
|