Last active
August 29, 2015 14:16
-
-
Save paulmilner/90f2e258c14715333e4c to your computer and use it in GitHub Desktop.
How to set up a Weld test
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
/* | |
Weld dependency for your POM: | |
<dependency> | |
<groupId>org.jboss.weld.se</groupId> | |
<artifactId>weld-se</artifactId> | |
<version>Whatever the latest version is!</version> | |
</dependency> | |
*/ | |
//The Application under test: | |
public class Application { | |
@Inject | |
String thing; | |
public boolean isInitialised() { | |
return true; | |
} | |
} | |
//For the test | |
public class WeldTest { | |
static WeldContainer container; | |
@BeforeClass | |
public static void setupClass() throws Exception { | |
Weld weld = new Weld(); | |
container = weld.initialize(); | |
} | |
@Test | |
public void application_initializes_ok throws Exception { | |
Application app = container.instance().select(Application.class).get(); | |
assertTrue(app.isInitialised()); //although the test would've failed anyway if injection failed | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment