Added:
trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/DefaultContainerTest.java
trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/LegacyContainerTest.java
trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/util/NonDuplicateStackTest.java
Removed:
trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/AutoWiringAdaptableContainerTest.java
Modified:
trunk/israfil-micro-container/src/main/java/net/israfil/micro/container/DefaultContainer.java
trunk/israfil-micro-container/src/main/java/net/israfil/micro/container/util/NonDuplicateStack.java
trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/LifecycleTest.java
trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/util/CyclicalDependencyDetectionTest.java
Log:
fix up tests, add more tests, rename some things. Also re-work
NonDuplicateStack so it's based on java.util.Stack
Modified: trunk/israfil-micro-container/src/main/java/net/israfil/micro/container/DefaultContainer.java
==============================================================================
---
trunk/israfil-micro-container/src/main/java/net/israfil/micro/container/DefaultContainer.java (original)
+++
trunk/israfil-micro-container/src/main/java/net/israfil/micro/container/DefaultContainer.java
Mon Aug 4 10:53:40 2008
@@ -116,7 +116,8 @@
}
public synchronized void start() {
- if (isRunning() || starting) return;
+ if (isRunning() ||
+ starting) return;
if (getParent() != null && !getParent().isRunning()) throw new
RuntimeException("Parent container is not started.");
this.starting = true;
if (failEarly) {
@@ -127,13 +128,29 @@
}
}
super.start();
+ starting = false;
}
public void registerType(Object key, Class componentType) {
- registerType(key,new IndependentAutoWiringAdapter(componentType));
+ registerType(key,componentType, 0);
+ }
+
+ public void registerType(Object key, Class componentType, long
timeout) {
+ registerType(key,new IndependentAutoWiringAdapter(componentType), timeout);
}
public void registerType(Object key, AutoWiringAdapter
componentAdapter) {
+ registerType(key,componentAdapter,0);
+ }
+
+ /**
+ * Registers a component for later instantiation and (optionally) startup.
+ *
+ * @param key the key by which this component will be identified in
the system
+ * @param componentAdapter an AutoWiringAdapter for creating this
component and listing its dependencies
+ * @param timeout an (optional) timeout applied to any startup lifecycle
+ */
+ public void registerType(Object key, AutoWiringAdapter
componentAdapter, long timeout) {
if (this.isRunning()) throw new RuntimeException("Cannot register
when container is started.");
// FIXME: Figure out whether to support parent registry checking.
Probably can't do it.
@@ -177,6 +194,8 @@
} catch (IllegalAccessException e) {
throw new CouldNotCreateComponentError("Could not create
component " + originalKey + " of type " + adapter.getType(),e);
} catch (InstantiationException e) {
+ throw new CouldNotCreateComponentError("Could not create
component " + originalKey + " of type " + adapter.getType(),e);
+ } catch (Throwable e) {
throw new CouldNotCreateComponentError("Could not create
component " + originalKey + " of type " + adapter.getType(),e);
}
}
Modified: trunk/israfil-micro-container/src/main/java/net/israfil/micro/container/util/NonDuplicateStack.java
==============================================================================
---
trunk/israfil-micro-container/src/main/java/net/israfil/micro/container/util/NonDuplicateStack.java (original)
+++
trunk/israfil-micro-container/src/main/java/net/israfil/micro/container/util/NonDuplicateStack.java
Mon Aug 4 10:53:40 2008
@@ -33,26 +33,21 @@
*/
package net.israfil.micro.container.util;
-import java.util.Vector;
+import java.util.Stack;
/**
- * A quick stack object which throws an IllegalArgumentException if an
+ * A simple stack object which throws an IllegalArgumentException if an
* attempt is made to push an object already contained within the stack.
*
* Primarily used for circular reference detection.
*
* @author <a href="mailto:cgr...@israfil.net">Christian Edward
Gruber </a>
*/
-public class NonDuplicateStack {
- private final Vector list = new Vector();
- public void push(Object o) {
- if (list.contains(o)) throw new IllegalArgumentException("Duplicate entry");
- list.addElement(o);
- }
- public Object pop() {
- Object o = list.elementAt(list.size()-1);
- list.removeElementAt(list.size()-1);
- return o;
+public class NonDuplicateStack extends Stack {
+
+ public Object push(Object item) {
+ if (contains(item)) throw new IllegalArgumentException("Duplicate item.");
+ return super.push(item);
}
- public String toString() { return list.toString(); }
+
}
Added: trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/DefaultContainerTest.java
==============================================================================
--- (empty file)
+++
trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/DefaultContainerTest.java
Mon Aug 4 10:53:40 2008
@@ -0,0 +1,284 @@
+/*
+ * Copyright (c) 2008 Israfil Consulting Services Corporation
+ * Copyright (c) 2008 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of
its contributors
+ * may be used to endorse or promote products derived from this
software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: Copyright.java 618 2008-04-14 14:03:03Z christianedwardgruber $
+ */
+package net.israfil.micro.container;
+
+
+import net.israfil.micro.container.adapters.AbstractAutoWiringAdapter;
+import net.israfil.micro.container.adapters.IndependentAutoWiringAdapter;
+
+import org.testng.Assert;
+
+public class DefaultContainerTest {
+
+
+ /** @testng.before-method alwaysRun = "true" */
+ public void setUp() {
+
+ }
+
+ /** @testng.after-method alwaysRun = "true" */
+ public void tearDown() {
+ }
+
+ public DefaultContainer createContainer() { return new
DefaultContainer(); }
+ public DefaultContainer createContainer(boolean tf) { return new
DefaultContainer(tf); }
+ public DefaultContainer createContainer(Container c) { return new
DefaultContainer(c); }
+ public DefaultContainer createContainer(Container c, boolean tf) {
return new DefaultContainer(c,tf); }
+ public TestableContainer createTestableContainer() { return new
TestableDefaultContainer(); }
+
+ /** @testng.test */
+ public void testAutoWiringContainer() {
+ TestableContainer container = createTestableContainer();
+ container.registerType(A.class, A1.class);
+ container.registerType(B.class,B.adapter);
+ container.registerType(D.class,D.adapter); // out of order
+ container.registerType(C.class, new AbstractAutoWiringAdapter(
+ C.class,
+ new Object[] {A.class}
+ ) {
+ public Object create(Object[] param) throws IllegalAccessException,
InstantiationException {
+ return new C((A)param[0]);
+ }
+ });
+ container.start();
+ Assert.assertFalse(container.isStored(A.class));
+ Assert.assertNotNull(container.getComponent(A.class));
+ Assert.assertTrue(container.isStored(A.class));
+ Assert.assertFalse(container.isStored(B.class));
+ Assert.assertNotNull(container.getComponent(B.class));
+ Assert.assertTrue(container.isStored(B.class));
+ Assert.assertFalse(container.isStored(C.class));
+ Assert.assertFalse(container.isStored(D.class));
+ Assert.assertNotNull(container.getComponent(D.class));
+ Assert.assertTrue(container.isStored(C.class));
+ Assert.assertTrue(container.isStored(D.class));
+ }
+
+ /** @testng.test
+ @testng.expected-exceptions
+ value
= "net.israfil.micro.container.error.UnsatisfiedDependencyError" */
+ public void testMissingDependenciesFailingLate() {
+ AutoWiringAdaptableContainer container = createContainer();
+ container.registerType(B.class,B.adapter);
+ container.start();
+ Assert.assertTrue(container.isRunning());
+ container.getComponent(B.class);
+ }
+
+ /** @testng.test */
+ public void testDelayedFailureWithMissingDependencies() {
+ AutoWiringAdaptableContainer container = createContainer();
+ container.registerType(B.class,B.adapter);
+ container.start();
+ }
+
+ /** @testng.test
+ @testng.expected-exceptions
+ value
= "net.israfil.micro.container.error.UnsatisfiedDependencyError" */
+ public void testMissingDependenciesFailingEarly() {
+ AutoWiringAdaptableContainer container = createContainer(true);
+ container.registerType(B.class,B.adapter);
+ container.start();
+ }
+
+ /** @testng.test */
+ public void testMultipleStartups() {
+ AutoWiringAdaptableContainer container = createContainer(true);
+ container.registerType(A.class,A1.class);
+ container.registerType(B.class,B.adapter);
+ container.start();
+ Assert.assertTrue(container.isRunning());
+ container.start(); // no error.
+ }
+
+ /** @testng.test
+ @testng.expected-exceptions
+ value = "java.lang.RuntimeException" */
+ public void testStartupWithUnstartedParent() {
+ AutoWiringAdaptableContainer parent = createContainer();
+ AutoWiringAdaptableContainer child = createContainer(parent);
+ parent.registerType(A.class,A1.class);
+ child.registerType(B.class,B.adapter);
+ child.start(); // failed to start parent.
+ }
+
+ /** @testng.test
+ @testng.expected-exceptions
+ value
= "net.israfil.micro.container.error.ComponentAlreadyRegisteredError" */
+ public void testDuplicateRegistration() {
+ AutoWiringAdaptableContainer container = createContainer();
+ container.registerType(A.class,A1.class);
+ container.registerType(A.class,new AutoWiringAdapter() {
+ public Object create(Object[] parameters) throws
IllegalAccessException, InstantiationException {
+ return null;
+ }
+ public Object[] dependencies() { return null; }
+ public Class getType() { return null; }
+ });
+ }
+
+ /** @testng.test
+ @testng.expected-exceptions
+ value = "java.lang.RuntimeException" */
+ public void testRegistryFailureAfterStart() {
+ AutoWiringAdaptableContainer container = createContainer();
+ container.registerType(A.class,A1.class);
+ container.registerType(B.class,B.adapter);
+ container.start();
+ container.registerType(D.class,D.adapter);
+ }
+
+ /** @testng.test
+ @testng.expected-exceptions
+ value
= "net.israfil.micro.container.error.CouldNotCreateComponentError" */
+ public void testIllegalAccessDuringConstruction() {
+ AutoWiringAdaptableContainer container = createContainer(true);
+ container.registerType(ComponentWithProtectedConstructor.class,ComponentWithProtectedConstructor.class);
+ container.start();
+ }
+
+ /** @testng.test
+ @testng.expected-exceptions
+ value
= "net.israfil.micro.container.error.CouldNotCreateComponentError" */
+ public void testInstantiationErrorDuringConstruction() {
+ AutoWiringAdaptableContainer container = createContainer(true);
+ container.registerType(A.class,A.class);
+ container.start();
+ }
+
+ /** @testng.test
+ @testng.expected-exceptions
+ value
= "net.israfil.micro.container.error.CouldNotCreateComponentError" */
+ public void testNullComponentCreation() {
+ AutoWiringAdaptableContainer container = createContainer(true);
+ container.registerType(A.class,new
IndependentAutoWiringAdapter(A.class) {
+ public Object create(Object[] param) throws IllegalAccessException,
InstantiationException {
+ return null;
+ }
+ });
+ container.start();
+ }
+ /** @testng.test
+ @testng.expected-exceptions
+ value
= "net.israfil.micro.container.error.CouldNotCreateComponentError" */
+ public void testArbitraryErrorInComponentCreation() {
+ AutoWiringAdaptableContainer container = createContainer(true);
+ container.registerType(A.class,new
IndependentAutoWiringAdapter(A.class) {
+ public Object create(Object[] param) throws IllegalAccessException,
InstantiationException {
+ throw new RuntimeException("Random error");
+ }
+ });
+ container.start();
+ }
+
+
+ /** @testng.test */
+ public void
testAutowiringWithDependencyInParentContainerWithEarlyInstantiation() {
+ AutoWiringAdaptableContainer parent = createContainer(true);
+ AutoWiringAdaptableContainer child = createContainer(parent,true);
+ parent.registerType(A.class,A1.class);
+ child.registerType(B.class,B.adapter);
+ parent.start();
+ child.start();
+ Assert.assertNotNull(child.getComponent(B.class));
+ }
+ /** @testng.test */
+ public void
testAutowiringWithDependencyInParentContainerWithLateIntantiation() {
+ AutoWiringAdaptableContainer parent = createContainer();
+ AutoWiringAdaptableContainer child = createContainer(parent);
+ parent.registerType(A.class,A1.class);
+ child.registerType(B.class,B.adapter);
+ parent.start();
+ child.start();
+ Assert.assertNotNull(child.getComponent(B.class));
+ }
+
+ public static abstract class A {
+ }
+ public static class A1 extends A {
+ }
+ public static class B {
+ private final A a;
+ public B(A a) {
+ if (a==null) throw new IllegalArgumentException("B cannot support
null constructor arguments.");
+ this.a = a;
+ }
+ public static final AutoWiringAdapter adapter = new AbstractAutoWiringAdapter(
+ B.class,
+ new Object[] {A.class}
+ ) {
+ public Object create(Object[] param) throws IllegalAccessException,
InstantiationException {
+ return new B((A)param[0]);
+ }
+ };
+ }
+ public static class C {
+ private final A a;
+ public C(A a) {
+ if (a==null) throw new IllegalArgumentException("C cannot support
null constructor arguments.");
+ this.a = a;
+ }
+ }
+ public static class D {
+ private final C c;
+ public D(C c) {
+ if (c==null) throw new IllegalArgumentException("D cannot support
null constructor arguments.");
+ this.c = c;
+ }
+ public static final AutoWiringAdapter adapter = new AbstractAutoWiringAdapter(
+ D.class,
+ new Object[] {C.class}
+ ) {
+ public Object create(Object[] param) throws IllegalAccessException,
InstantiationException {
+ return new D((C)param[0]);
+ }
+ };
+ }
+
+ public static class ComponentWithProtectedConstructor {
+ protected ComponentWithProtectedConstructor() {}
+ }
+
+ public static interface TestableContainer extends
AutoWiringAdaptableContainer {
+ public boolean isStored(Object key);
+ }
+
+ public static class TestableDefaultContainer extends DefaultContainer
implements TestableContainer {
+ public boolean isStored(Object key) {
+ return super.isStored(key);
+ }
+ }
+
+
+}
Added: trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/LegacyContainerTest.java
==============================================================================
--- (empty file)
+++
trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/LegacyContainerTest.java
Mon Aug 4 10:53:40 2008
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2008 Israfil Consulting Services Corporation
+ * Copyright (c) 2008 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of
its contributors
+ * may be used to endorse or promote products derived from this
software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: Copyright.java 618 2008-04-14 14:03:03Z christianedwardgruber $
+ */
+package net.israfil.micro.container;
+
+
+
+public class LegacyContainerTest extends DefaultContainerTest {
+
+ public DefaultContainer createContainer() { return new
DefaultAutoWiringAdaptableContainer(); }
+ public DefaultContainer createContainer(boolean tf) { return new
DefaultAutoWiringAdaptableContainer(tf); }
+ public DefaultContainer createContainer(Container c) { return new
DefaultAutoWiringAdaptableContainer(c); }
+ public DefaultContainer createContainer(Container c, boolean tf) {
return new DefaultAutoWiringAdaptableContainer(c,tf); }
+ public TestableContainer createTestableContainer() { return new
TestableLegacyContainer(); }
+
+ public static class TestableLegacyContainer extends
DefaultAutoWiringAdaptableContainer implements TestableContainer {
+ public boolean isStored(Object key) {
+ return super.isStored(key);
+ }
+ }
+
+}
Modified: trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/LifecycleTest.java
==============================================================================
---
trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/LifecycleTest.java (original)
+++
trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/LifecycleTest.java
Mon Aug 4 10:53:40 2008
@@ -72,6 +72,19 @@
container.start();
container.getComponent(A.class);
Assert.assertTrue(a1.isRunning());
+ }
+
+ /** @testng.test */
+ public void testStartupOfStartedComponent() {
+ AutoWiringAdaptableContainer container = new DefaultContainer();
+ final A2 a2 = new A2();
+ a2.start();
+ container.registerType(A.class, new
IndependentAutoWiringAdapter(A.class) {
+ public Object create(Object[] args) { return a2; }
+ });
+ container.start();
+ container.getComponent(A.class);
+ Assert.assertEquals(a2.invoked,1);
}
/** @testng.test */
@@ -104,9 +117,19 @@
public static interface A {
}
+
public static class A1 extends AbstractStartable implements A {
public void start() { super.start(); }
}
+
+ public static class A2 extends AbstractStartable implements A {
+ public int invoked = 0;
+ public void start() {
+ super.start();
+ invoked++;
+ }
+ }
+
public static class B {
private final A a;
public B(A a) {
Modified: trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/util/CyclicalDependencyDetectionTest.java
==============================================================================
---
trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/util/CyclicalDependencyDetectionTest.java (original)
+++
trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/util/CyclicalDependencyDetectionTest.java
Mon Aug 4 10:53:40 2008
@@ -63,6 +63,11 @@
}
}
+ /** @testng.test */
+ public void testToSatisfyCoberturasSillyRule() {
+ CyclicalReferenceDetectionUtil util = new CyclicalReferenceDetectionUtil(){};
+ }
+
/** @testng.test
@testng.expected-exceptions
value
= "net.israfil.micro.container.error.CyclicalDependencyError" */
Added: trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/util/NonDuplicateStackTest.java
==============================================================================
--- (empty file)
+++
trunk/israfil-micro-container/src/test/java/net/israfil/micro/container/util/NonDuplicateStackTest.java
Mon Aug 4 10:53:40 2008
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2008 Israfil Consulting Services Corporation
+ * Copyright (c) 2008 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Israfil Consulting Services nor the names of
its contributors
+ * may be used to endorse or promote products derived from this
software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * $Id: Copyright.java 618 2008-04-14 14:03:03Z christianedwardgruber $
+ */
+package net.israfil.micro.container.util;
+
+import java.util.Stack;
+
+import org.testng.Assert;
+
+
+public class NonDuplicateStackTest {
+
+ /** @testng.test */
+ public void testBasicStackBehaviour() {
+ String s1 = "Hi.";
+ String s2 = "Hi";
+ String s3 = "Bye.";
+ Stack stack = new NonDuplicateStack();
+ stack.push(s1);
+ stack.push(s2);
+ stack.push(s3);
+ Assert.assertSame(stack.pop(),s3);
+ Assert.assertSame(stack.pop(),s2);
+ Assert.assertSame(stack.pop(),s1);
+ }
+
+ /** @testng.test
+ @testng.expected-exceptions
+ value = "java.lang.IllegalArgumentException" */
+ public void testDuplicateHandlingByObjectRef() {
+ Object o1 = new Object();
+ Object o2 = new Object();
+ Object o3 = new Object();
+ Stack stack = new NonDuplicateStack();
+ stack.push(o1);
+ stack.push(o2);
+ stack.push(o3);
+ stack.push(o2);
+ }
+
+ /** @testng.test
+ @testng.expected-exceptions
+ value = "java.lang.IllegalArgumentException" */
+ public void testDuplicateHandlingByValue() {
+ String s1 = "Hi.";
+ String s2 = "Hi";
+ String s3 = "Bye.";
+ String s4 = "Hi";
+ Stack stack = new NonDuplicateStack();
+ stack.push(s1);
+ stack.push(s2);
+ stack.push(s3);
+ stack.push(s4);
+ }
+
+}