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.modifier;
008:
009: import junit.framework.TestCase;
010:
011: /**
012: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
013: */
014: public class ModifierTest extends TestCase {
015: private static String s_logString = "";
016:
017: private int privateField;
018:
019: protected int protectedField;
020:
021: public int publicField;
022:
023: public ModifierTest() {
024: }
025:
026: public ModifierTest(String name) {
027: super (name);
028: }
029:
030: public void testPrivateMethod() {
031: s_logString = "";
032: privateMethod();
033: assertEquals("call execution invocation execution call ",
034: s_logString);
035: }
036:
037: public void testProtectedMethod() {
038: s_logString = "";
039: protectedMethod();
040: assertEquals("call execution invocation execution call ",
041: s_logString);
042: }
043:
044: public void testPublicMethod() {
045: s_logString = "";
046: publicMethod();
047: assertEquals("call execution invocation execution call ",
048: s_logString);
049: }
050:
051: public void testStaticFinalMethod() {
052: s_logString = "";
053: staticFinalMethod();
054: assertEquals("call invocation call ", s_logString);
055: }
056:
057: public void testSetPublicField() {
058: s_logString = "";
059: publicField = 0;
060: assertEquals("set set ", s_logString);
061: }
062:
063: public void testSetPrivateField() {
064: s_logString = "";
065: privateField = 0;
066: assertEquals("set set ", s_logString);
067: }
068:
069: public void testSetProtectedField() {
070: s_logString = "";
071: protectedField = 0;
072: assertEquals("set set ", s_logString);
073: }
074:
075: public void testGetPublicField() {
076: s_logString = "";
077: int i = publicField;
078: assertEquals("get get ", s_logString);
079: }
080:
081: public void testGetPrivateField() {
082: s_logString = "";
083: int i = privateField;
084: assertEquals("get get ", s_logString);
085: }
086:
087: public void testGetProtectedField() {
088: s_logString = "";
089: int i = protectedField;
090: assertEquals("get get ", s_logString);
091: }
092:
093: public static void main(String[] args) {
094: junit.textui.TestRunner.run(suite());
095: }
096:
097: public static junit.framework.Test suite() {
098: return new junit.framework.TestSuite(ModifierTest.class);
099: }
100:
101: // ==== methods to test ====
102: public static void log(final String wasHere) {
103: s_logString += wasHere;
104: }
105:
106: private void privateMethod() {
107: log("invocation ");
108: }
109:
110: protected void protectedMethod() {
111: log("invocation ");
112: }
113:
114: public void publicMethod() {
115: log("invocation ");
116: }
117:
118: static final void staticFinalMethod() {
119: log("invocation ");
120: }
121: }
|