X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fgeneral%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fcore%2FDefaultScopeTest.java;fp=system%2Fgeneral%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fcore%2FDefaultScopeTest.java;h=8458c326e5265d483feda55dc0d6e4895a85be60;hb=001d69a3cfa9c4d949963d222c05a3134b594ddb;hp=0000000000000000000000000000000000000000;hpb=b7f387ca0178938325ce7107222188d3912fc1cb;p=utils diff --git a/system/general/src/test/java/org/wamblee/system/core/DefaultScopeTest.java b/system/general/src/test/java/org/wamblee/system/core/DefaultScopeTest.java new file mode 100644 index 00000000..8458c326 --- /dev/null +++ b/system/general/src/test/java/org/wamblee/system/core/DefaultScopeTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2008 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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 junit.framework.TestCase; + +public class DefaultScopeTest extends TestCase { + + public void testLookup() { + ProvidedInterface provider = new DefaultProvidedInterface("x", Integer.class); + Scope scope = new DefaultScope(new ProvidedInterface[0]); + + assertNull(provider.getUniqueId()); + scope.publishInterface(provider, 100); + assertNotNull(provider.getUniqueId()); + } + + public void testNestedLookup() { + ProvidedInterface provider1 = new DefaultProvidedInterface("x", Integer.class); + Scope parent = new DefaultScope(new ProvidedInterface[0]); + + parent.publishInterface(provider1, 100); + + ProvidedInterface provider2 = new DefaultProvidedInterface("y", String.class); + Scope child = new DefaultScope(new ProvidedInterface[0], parent); + + child.publishInterface(provider2, "hallo"); + + assertNotNull(provider1.getUniqueId()); + assertNotNull(provider2.getUniqueId()); + + assertFalse(provider1.getUniqueId().equals(provider2.getUniqueId())); + + assertEquals(100, child.getInterfaceImplementation(provider1, Integer.class).intValue()); + assertEquals("hallo", child.getInterfaceImplementation(provider2, String.class)); + } + +}