Package guiceberry2_junit3.tutorial_1_server

Source Code of guiceberry2_junit3.tutorial_1_server.PetStoreEnv0Simple$PetStoreServerStarter

package guiceberry2_junit3.tutorial_1_server;

import com.google.inject.Inject;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.testing.guiceberry.GuiceBerryEnvMain;
import com.google.inject.testing.guiceberry.junit3.GuiceBerryJunit3Env;

import guiceberry2_junit3.tutorial_1_server.prod.MyPetStoreServer;
import guiceberry2_junit3.tutorial_1_server.prod.PortNumber;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;


public class PetStoreEnv0Simple extends GuiceBerryJunit3Env {
 
  @Provides
  @PortNumber
  int getPortNumber(MyPetStoreServer server) {
    return server.getPortNumber();
  }
 
  @Provides
  WebDriver getWebDriver() {
    WebDriver driver = new HtmlUnitDriver();
    return driver;
  }
 
  @Provides
  @Singleton
  protected MyPetStoreServer buildPetStoreServer() {
    return new MyPetStoreServer(8080);
  }
 
  @Override
  protected void configure() {
    super.configure();
    bind(GuiceBerryEnvMain.class).to(PetStoreServerStarter.class);
  }
 
  private static final class PetStoreServerStarter implements GuiceBerryEnvMain {
   
    @Inject
    private MyPetStoreServer myPetStoreServer;
   
    public void run() {
      // Starting a server should never be done in a @Provides method
      // (or inside Provider's get).
      myPetStoreServer.start();
    }
  }
}
TOP

Related Classes of guiceberry2_junit3.tutorial_1_server.PetStoreEnv0Simple$PetStoreServerStarter

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.