X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fgeneral%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fcore%2FEnvironment.java;h=6a39b645688b3f9fbaeb0e94a63d8d8390586593;hb=17775e14ecfb286e59f67117e5cee7e21e95ab1f;hp=d2c052715e7089f8a4a7a2d0a3b9584fe47aedc7;hpb=32a8562695029cf13d915bc7941a61fe07ff0005;p=utils diff --git a/system/general/src/test/java/org/wamblee/system/core/Environment.java b/system/general/src/test/java/org/wamblee/system/core/Environment.java index d2c05271..6a39b645 100644 --- a/system/general/src/test/java/org/wamblee/system/core/Environment.java +++ b/system/general/src/test/java/org/wamblee/system/core/Environment.java @@ -1,5 +1,5 @@ /* - * Copyright 2007 the original author or authors. + * Copyright 2005-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,77 +12,104 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ package org.wamblee.system.core; -import javax.sql.DataSource; - import org.wamblee.system.core.AbstractComponent; import org.wamblee.system.core.DefaultProvidedInterface; import org.wamblee.system.core.ProvidedInterface; import org.wamblee.system.core.RequiredInterface; + import org.wamblee.test.EventTracker; +import javax.sql.DataSource; + +/** + * + * @author $author$ + * @version $Revision$ + */ public class Environment extends AbstractComponent { + private static int COUNT = 0; + + private EventTracker tracker; + + private double random; + + private int integer; - private static final ProvidedInterface[] provided(String aPrefix) { - return new ProvidedInterface[] { - new DefaultProvidedInterface(aPrefix + "datasource", String.class), - new DefaultProvidedInterface(aPrefix + "integer", Integer.class) }; - } - - private EventTracker _tracker; - private double _random; - - public Environment() { - this("environment"); - } - - public Environment(String aName) { - this(aName, ""); + /** + * Creates a new Environment object. + */ + public Environment() { + this("environment"); } - - public Environment(String aName, String aPrefix) { + + /** + * Creates a new Environment object. + * + */ + public Environment(String aName) { + this(aName, ""); + } + + /** + * Creates a new Environment object. + * + */ + public Environment(String aName, String aPrefix) { super(aName, provided(aPrefix), new RequiredInterface[0]); - _random = Math.random(); + random = Math.random(); + integer = COUNT++; } + /** + * Creates a new Environment object. + * + */ + public Environment(EventTracker aTracker) { + this(); + tracker = aTracker; + } + + private static final ProvidedInterface[] provided(String aPrefix) { + return new ProvidedInterface[] { + new DefaultProvidedInterface(aPrefix + "datasource", String.class), + new DefaultProvidedInterface(aPrefix + "integer", Integer.class) }; + } + + public Integer getInteger() { + return integer; + } + + public String getString() { + return getName() + ".hello"; + } + @Override + protected Object doStart(Scope aScope) { + addInterface(getProvidedInterfaces().get(0), getString(), aScope); + addInterface(getProvidedInterfaces().get(1), getInteger(), aScope); + track("start." + getName()); - public Environment(EventTracker aTracker) { - this(); - _tracker = aTracker; - } - - public Integer getInteger() { - return 2; - } - - public String getString() { - return getName() + ".hello"; - } - - @Override - protected Object doStart(Scope aScope) { - addInterface(getProvidedInterfaces().get(0), getString(), aScope); - addInterface(getProvidedInterfaces().get(1), getInteger(), aScope); - track("start." + getName()); - return _random; - } - - @Override - protected void doStop(Object aRuntime) { - track("stop." + getName()); - if (_random != (Double) aRuntime) { - throw new IllegalArgumentException("Wrong runtime: expected " - + _random + " but got " + aRuntime); - } - } - - private void track(String aString) { - if (_tracker == null) { - return; - } - _tracker.eventOccurred(aString); - } + return random; + } + + @Override + protected void doStop(Object aRuntime) { + track("stop." + getName()); + + if (random != (Double) aRuntime) { + throw new IllegalArgumentException("Wrong runtime: expected " + + random + " but got " + aRuntime); + } + } + + private void track(String aString) { + if (tracker == null) { + return; + } + + tracker.eventOccurred(aString); + } }