ArbitraryBroadcastTest.java :  » Inversion-of-Control » guice-2.0 » com » google » inject » lifecycle » Java Open Source

Java Open Source » Inversion of Control » guice 2.0 
guice 2.0 » com » google » inject » lifecycle » ArbitraryBroadcastTest.java
package com.google.inject.lifecycle;

import com.google.inject.Guice;
import com.google.inject.Singleton;
import junit.framework.TestCase;

/** @author dhanji@gmail.com (Dhanji R. Prasanna) */
public class ArbitraryBroadcastTest extends TestCase {
  private static int called;

  public final void testCallable() {
    called = 0;
    Lifecycle lifecycle = Guice.createInjector(new LifecycleModule() {

      @Override
      protected void configureLifecycle() {
        bind(Runnable.class).to(AClass.class).in(Singleton.class);
        bind(AClass.class).in(Singleton.class);

        callable(Runnable.class);
      }

    }).getInstance(Lifecycle.class);

    lifecycle
      .broadcast(Runnable.class)
      .run();

    assertEquals(2, called);
  }

  public static class AClass implements Runnable {
    public void run() {
      called++;
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.