Package jfun.yan.containers

Examples of jfun.yan.containers.DefaultContainer


  private static TestSuite suite(){
    return new TestSuite(BaseContainerTestCase.class);
  }
    protected final DefaultContainer
    createPicoContainerWithDependsOnTouchableOnly(){
      DefaultContainer yan = new DefaultContainer();
      yan.registerConstructor(DependsOnTouchable.class);
      return yan;

    }
View Full Code Here


      return yan;

    }

    protected final DefaultContainer createPicoContainerWithTouchableAndDependsOnTouchable() {
        DefaultContainer yan = createPicoContainerWithDependsOnTouchableOnly();
        yan.registerConstructor(Touchable.class, SimpleTouchable.class);
        return yan;
    }
View Full Code Here

                yan.getInstance(DependsOnTouchable.class) instanceof DependsOnTouchable);
        assertNull("should not have non existent component", yan.getComponent(Map.class));
    }

    public void testRegistersSingleInstance(){
        DefaultContainer yan = new DefaultContainer();
        StringBuffer sb = new StringBuffer();
        yan.registerValue(sb);
        yan.verify();
        assertSame(sb, yan.getInstance(StringBuffer.class));
    }
View Full Code Here

          fail("should need a Touchable");
      } catch (jfun.yan.YanException e) {
      }
  }
    public void testExternallyInstantiatedObjectsCanBeRegistgeredAndLookedUp(){
        DefaultContainer yan = new DefaultContainer();
        final HashMap map = new HashMap();
        yan.registerValue(Map.class, map);
        yan.verify();
        assertSame(map, yan.getInstance(Map.class));
    }
View Full Code Here

        assertSame(map, yan.getInstance(Map.class));
    }


    public void testLookupWithUnregisteredKeyReturnsNull(){
        DefaultContainer yan = new DefaultContainer();
        assertNull(yan.getComponent(String.class));
    }
View Full Code Here

    }


    public void testCyclicDependencyThrowsCyclicDependencyException()
    throws Exception{
        Container yan = new DefaultContainer();
        yan.registerConstructor(ComponentB.class);
        yan.registerConstructor(ComponentD.class);
        yan.registerConstructor(ComponentE.class);
        yan = trans(yan);

        try {
            yan.getInstance(ComponentD.class);
            fail("CyclicDependencyException expected");
        } catch (jfun.yan.CyclicDependencyException e) {
            // CyclicDependencyException reports now the stack.
            //final List dependencies = Arrays.asList(ComponentD.class.getConstructors()[0].getParameterTypes());
            //final List dependencies = Arrays.asList(new Class[]{ComponentD.class, ComponentE.class, ComponentD.class});
View Full Code Here

    private void assertProperty(YanException e, int i, Class c, Object k){
      final Stack trace = e.getResolutionTrace();
      assertEquals(new PropertyEntry(c, k), trace.get(i));
    }
    public void testVerifyCyclicDependencyThrowsCyclicDependencyException() {
      DefaultContainer yan = new DefaultContainer();
      yan.registerConstructor(ComponentB.class);
      yan.registerConstructor(ComponentD.class);
      yan.registerConstructor(ComponentE.class);

      try {
          yan.verify();
          fail("CyclicDependencyException expected");
      } catch (jfun.yan.CyclicDependencyException e) {
        assertEquals(3, e.getResolutionTrace().size());
        assertParameter(e, 0, ComponentE.class, 0);
        assertParameter(e, 1, ComponentD.class, 0);
View Full Code Here

      } catch (StackOverflowError e) {
          fail();
      }
  }
    public void testRemovalNonRegisteredComponentAdapterWorksAndReturnsNull() {
        final DefaultContainer picoContainer = new DefaultContainer();
        picoContainer.unregisterComponent("COMPONENT DOES NOT EXIST");
    }
View Full Code Here

            this.washable = washable;
        }
    }

    public void testSameInstanceCanBeUsedAsDifferentType() {
        DefaultContainer yan = new DefaultContainer();
        yan.registerConstructor("wt", WashableTouchable.class);
        yan.registerConstructor("nw", NeedsWashable.class);
        yan.registerConstructor("nt", NeedsTouchable.class);

        NeedsWashable nw = (NeedsWashable) yan.getInstance("nw");
        NeedsTouchable nt = (NeedsTouchable) yan.getInstance("nt");
        assertSame(nw.washable, nt.touchable);
    }
View Full Code Here

        }
    }

    // http://jira.codehaus.org/secure/ViewIssue.jspa?key=PICO-52
    public void testPico52() {
        DefaultContainer yan = new DefaultContainer();

        yan.registerComponent("foo",
            Components.singleton(
                Components.withArguments(
                Components.ctor(JMSService.class),
                new jfun.yan.Creator[]{
                    Components.value("0"),
                    Components.value("something")
                })
            )
        );
        JMSService jms = (JMSService) yan.getInstance("foo");
        assertEquals("0", jms.serverid);
        assertEquals("something", jms.path);
    }
View Full Code Here

TOP

Related Classes of jfun.yan.containers.DefaultContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.