Created
December 1, 2010 22:42
-
-
Save rdammkoehler/724378 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jerseyandguice; | |
import static jerseyandguice.GuicedServletAssertion.assertInstantiablity; | |
import static jerseyandguice.GuicedServletAssertion.assertProvisioningType; | |
import static jerseyandguice.GuicedServletAssertion.expose; | |
import static org.testng.Assert.assertNotNull; | |
import org.testng.annotations.BeforeClass; | |
import org.testng.annotations.Test; | |
import com.google.inject.Injector; | |
import com.google.inject.ProvisionException; | |
public class GuiceWiringTest { | |
private Injector injector; | |
@BeforeClass | |
public void guicify() { | |
injector = new JGServletContextListener().getInjector(); | |
} | |
@Test | |
public void shouldCreateBogoServlet() throws Exception { | |
assertInstantiablity(injector, BogoServlet.class); | |
} | |
@Test(expectedExceptions=ProvisionException.class) | |
public void shouldFailToCreateDependancyBecauseOfScope() { | |
injector.getInstance(Dependancy.class); | |
} | |
@Test | |
public void shouldCreateDependancy() throws Exception { | |
assertInstantiablity(injector, Dependancy.class); | |
} | |
@Test | |
public void shouldProvideDefaultDependancyForDependancy() throws Exception { | |
assertProvisioningType(injector, Dependancy.class, DefaultDependancy.class); | |
} | |
@Test | |
public void shouldExposeBogoServlet() throws Exception { | |
BogoServlet bogoServlet = expose(injector, BogoServlet.class); | |
assertNotNull(bogoServlet); | |
assertNotNull(bogoServlet.getDependancy()); | |
} | |
@Test | |
public void shouldWireDependancyIntoBogoServlet() { | |
BogoServlet bogoServlet = (BogoServlet) injector.getInstance(BogoServlet.class); | |
assertNotNull(bogoServlet.getDependancy()); | |
} | |
@Test | |
public void shouldProvideDependancy() { | |
assertNotNull(injector.getProvider(Dependancy.class)); | |
} | |
@Test | |
public void shouldProvideBogoServlet() { | |
assertNotNull(injector.getProvider(BogoServlet.class)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment