Package org.nanocontainer.nanowar.chain

Source Code of org.nanocontainer.nanowar.chain.ContainerChainTest$MockStartable

package org.nanocontainer.nanowar.chain;


import org.picocontainer.MutablePicoContainer;
import org.picocontainer.PicoContainer;
import org.picocontainer.Startable;
import org.picocontainer.defaults.DefaultPicoContainer;

import junit.framework.TestCase;

/**
* test capabilities of container chains
* @author Konstantin Pribluda
*/
public class ContainerChainTest extends TestCase {

 
  /**
   * empty chain shall
   * @throws Exception
   */
  public void testEmptyChain()  {
    ContainerChain chain = new ContainerChain();
    assertNull(chain.getLast());
  }
 
 
  public void testAddingContainerSetsItToLast() {
    ContainerChain chain = new ContainerChain();
    PicoContainer container = new DefaultPicoContainer();
   
    chain.addContainer(container);
   
    assertSame(container,chain.getLast());
   
  }
 
 
  public void testStartStopPropagation() {
    ContainerChain chain = new ContainerChain();
    MutablePicoContainer first = new DefaultPicoContainer();
 
    first.registerComponentInstance(new MockStartable());
    chain.addContainer(first);
   
    MutablePicoContainer second = new DefaultPicoContainer();
    second.registerComponentInstance(new MockStartable());
   
    chain.addContainer(second);
   
    chain.start();
    chain.stop();
   
   
    MockStartable startable = (MockStartable) first.getComponentInstanceOfType(MockStartable.class);
    assertTrue(startable.isStarted());
    assertTrue(startable.isStopped());
   
    startable = (MockStartable) second.getComponentInstanceOfType(MockStartable.class);
    assertTrue(startable.isStarted());
    assertTrue(startable.isStopped());
   
  }
 
  class MockStartable implements Startable {
    boolean started = false;
    boolean stopped = false;

    public void start() {
      setStarted(true);
    }

    public void stop() {
      setStopped(true);
    }
   
    /**
     * @return Returns the started.
     */
    public boolean isStarted() {
      return started;
    }
    /**
     * @param started The started to set.
     */
    public void setStarted(boolean started) {
      this.started = started;
    }
    /**
     * @return Returns the stopped.
     */
    public boolean isStopped() {
      return stopped;
    }
    /**
     * @param stopped The stopped to set.
     */
    public void setStopped(boolean stopped) {
      this.stopped = stopped;
    }
  }
}
TOP

Related Classes of org.nanocontainer.nanowar.chain.ContainerChainTest$MockStartable

TOP
Copyright © 2018 www.massapi.com. 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.