001: /* ====================================================================
002: The Jicarilla Software License
003:
004: Copyright (c) 2003 Leo Simons.
005: All rights reserved.
006:
007: Permission is hereby granted, free of charge, to any person obtaining
008: a copy of this software and associated documentation files (the
009: "Software"), to deal in the Software without restriction, including
010: without limitation the rights to use, copy, modify, merge, publish,
011: distribute, sublicense, and/or sell copies of the Software, and to
012: permit persons to whom the Software is furnished to do so, subject to
013: the following conditions:
014:
015: The above copyright notice and this permission notice shall be
016: included in all copies or substantial portions of the Software.
017:
018: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025: ==================================================================== */
026: package org.jicarilla.container.tck;
027:
028: import org.jicarilla.container.tck.components.AbstractComponent;
029: import org.jicarilla.container.tck.components.interfaces.Bart;
030: import org.jicarilla.container.tck.components.interfaces.Homer;
031: import org.jicarilla.container.tck.components.interfaces.Lisa;
032: import org.jicarilla.container.tck.components.interfaces.Maggie;
033: import org.jicarilla.container.tck.components.interfaces.Marge;
034: import org.jicarilla.container.tck.components.interfaces.Script;
035: import org.jicarilla.container.tck.components.type3.rich.AllInTheFamilyScript;
036: import org.jicarilla.container.tck.util.InvocationRecorder;
037: import org.jicarilla.container.tck.util.InvocationRecorderProvider;
038:
039: import java.util.List;
040:
041: /**
042: *
043: *
044: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
045: * @version $Id: AbstractAllInTheFamilyTestCase.java,v 1.3 2004/04/03 12:09:20 lsimons Exp $
046: */
047: public abstract class AbstractAllInTheFamilyTestCase extends
048: AbstractTCKTestCase {
049: // ----------------------------------------------------------------------
050: // Properties
051: // ----------------------------------------------------------------------
052: protected Script script;
053: protected Homer homer;
054: protected Marge marge;
055: protected Bart bart;
056: protected Lisa lisa;
057: protected Maggie maggie;
058:
059: // ----------------------------------------------------------------------
060: // The test contract
061: // ----------------------------------------------------------------------
062: protected abstract Script getAllInTheFamilyScript();
063:
064: protected abstract Homer getHomer();
065:
066: protected abstract Marge getMarge();
067:
068: protected abstract Bart getBart();
069:
070: protected abstract Lisa getLisa();
071:
072: protected abstract Maggie getMaggie();
073:
074: public void setUp() throws Exception {
075: super .setUp();
076:
077: script = getAllInTheFamilyScript();
078: homer = getHomer();
079: marge = getMarge();
080: bart = getBart();
081: lisa = getLisa();
082: maggie = getMaggie();
083: }
084:
085: public final void testGetHomerProvidesAValidResult() {
086: assertNotNull(
087: "the result of the call to getHomer() may not be null",
088: homer);
089: assertTrue(
090: "the result of the call to getHomer() must be an instance "
091: + "of InvocationRecorderProvider",
092: homer instanceof InvocationRecorderProvider);
093: }
094:
095: public final void testGetMargeProvidesAValidResult() {
096: assertNotNull(
097: "the result of the call to getMarge() may not be null",
098: marge);
099: assertTrue(
100: "the result of the call to getMarge() must be an instance "
101: + "of InvocationRecorderProvider",
102: marge instanceof InvocationRecorderProvider);
103: }
104:
105: public final void testGetBartProvidesAValidResult() {
106: assertNotNull(
107: "the result of the call to getBart() may not be null",
108: bart);
109: assertTrue(
110: "the result of the call to getBart() must be an instance "
111: + "of InvocationRecorderProvider",
112: bart instanceof InvocationRecorderProvider);
113: }
114:
115: public final void testGetLisaProvidesAValidResult() {
116: assertNotNull(
117: "the result of the call to getLisa() may not be null",
118: lisa);
119: assertTrue(
120: "the result of the call to getLisa() must be an instance "
121: + "of InvocationRecorderProvider",
122: lisa instanceof InvocationRecorderProvider);
123: }
124:
125: public final void testGetMaggieProvidesAValidResult() {
126: assertNotNull(
127: "the result of the call to getMaggie() may not be null",
128: maggie);
129: assertTrue("the result of the call to getMaggie() must be an "
130: + "instance of InvocationRecorderProvider",
131: maggie instanceof InvocationRecorderProvider);
132: }
133:
134: // ----------------------------------------------------------------------
135: // actual behavioural tests: Script
136: // ----------------------------------------------------------------------
137:
138: public final void testScriptReceivesDependenciesAtCorrectTime() {
139: final int firstcall = 0;
140: final int maxcall = 5;
141:
142: assertMethodCallInRange(script, "setHomer", firstcall, maxcall);
143: assertMethodCallInRange(script, "setMarge", firstcall, maxcall);
144: assertMethodCallInRange(script, "setBart", firstcall, maxcall);
145: assertMethodCallInRange(script, "setLisa", firstcall, maxcall);
146: assertMethodCallInRange(script, "setMaggie", firstcall, maxcall);
147: }
148:
149: public final void testScriptReceivesNonNullDependencies() {
150: assertMethodCalledOnceWithNonNullArguments(script, "setHomer");
151: assertMethodCalledOnceWithNonNullArguments(script, "setMarge");
152: assertMethodCalledOnceWithNonNullArguments(script, "setBart");
153: assertMethodCalledOnceWithNonNullArguments(script, "setLisa");
154: assertMethodCalledOnceWithNonNullArguments(script, "setMaggie");
155: assertMethodCalledOnceWithNonNullArguments(script, "setBart");
156: }
157:
158: public final void testScriptRunsToCompletionWithoutErrors() {
159: script.runEpisode();
160: }
161:
162: public final void testScriptRunsCorrectly() {
163: AbstractComponent.resetLogger();
164: InvocationRecorder log = AbstractComponent.getAggregateLogger();
165: script.runEpisode();
166: List invocations = log.getInvocations();
167:
168: assertEquals(5, invocations.size());
169:
170: assertMethodCallSequence(log, new String[] { "runEpisode",
171: "burp", "frown", "swear", "actSmart" });
172: }
173: }
|