package guiceberry2_junit3.tutorial_1_server; import com.google.common.testing.TearDown; import com.google.inject.Inject; import com.google.inject.testing.guiceberry.GuiceBerryEnv; import com.google.inject.testing.guiceberry.TestId; import com.google.inject.testing.guiceberry.junit3.GuiceBerryJunit3TestCase; import guiceberry2_junit3.tutorial_1_server.PetStoreEnv3CookiesControlledPotm.PetStoreModuleWithTestIdBasedOverride; import guiceberry2_junit3.tutorial_1_server.prod.PetOfTheMonth; @GuiceBerryEnv(Tutorial1Envs.PET_STORE_ENV_3_COOKIES_BASED_POTM) public class Example3ManualControlledInjectionThroughCookieTest extends GuiceBerryJunit3TestCase { @Inject WelcomeTestPage welcomeTestPage; @Inject private TestId testId; public void testDogAsPotm() { PetOfTheMonth expected = PetOfTheMonth.DOG; PetStoreModuleWithTestIdBasedOverride.override.put(testId, expected); // register a tearDown, so that at the end of the test, // the override is set to null again addTearDown(new TearDown() { public void tearDown() { PetStoreModuleWithTestIdBasedOverride.override.remove(testId); } }); welcomeTestPage.goTo(); welcomeTestPage.assertPetOfTheMonth(expected); } public void testCatAsPotm() { PetOfTheMonth expected = PetOfTheMonth.CAT; PetStoreModuleWithTestIdBasedOverride.override.put(testId, expected); // register a tearDown, so that at the end of the test, // the override is set to null again addTearDown(new TearDown() { public void tearDown() { PetStoreModuleWithTestIdBasedOverride.override.remove(testId); } }); welcomeTestPage.goTo(); welcomeTestPage.assertPetOfTheMonth(expected); } }