public ToothPickRule(Object test, Object scopeName) { this.testModule = new ToothPickTestModule(test); if (scopeName != null) { setScopeName(scopeName); } }
public <T> T getInstance(Class<T> clazz) { return getInstance(clazz, null); }
@Test(expected = IllegalArgumentException.class) public void test() throws Exception { new ToothPickRule(this, "Foo").setRootRegistryPackage("foo"); } }
@Test public void testSetScopeName() throws Exception { toothPickRuleWithoutScopeName.setScopeName("Bar"); assertThat(toothPickRuleWithoutScopeName.getScope(), notNullValue()); assertThat(toothPickRuleWithoutScopeName.getScope().getName(), is((Object) "Bar")); assertThat(toothPickRuleWithoutScopeName.getTestModule(), notNullValue()); } }
@Test public void testGetInstance_shouldReturnNamedBinding_whenAskingNamedBinding() throws Exception { //GIVEN ModuleWithNamedBindings moduleWithNamedBindings = new ModuleWithNamedBindings(); toothPickRule.getScope().installModules(moduleWithNamedBindings); //WHEN entryPoint = toothPickRule.getInstance(EntryPoint.class, "Foo"); //THEN assertThat(entryPoint, notNullValue()); assertThat(entryPoint, sameInstance(moduleWithNamedBindings.instance)); }
@Test public void testMultiply() throws Exception { //GIVEN expect(mockComputer.compute()).andReturn(4); expect(mockComputer2.compute()).andReturn(4); replay(mockComputer, mockComputer2); toothPickRule.inject(simpleEntryPointUnderTest); //WHEN int result = simpleEntryPointUnderTest.multiply(); //THEN assertThat(result, is(48)); verify(mockComputer); } }
@Test public void testScopeNameSetByConstruction() throws Exception { assertThat(toothPickRule.getScope(), notNullValue()); assertThat(toothPickRule.getScope().getName(), is((Object) "Foo")); assertThat(toothPickRule.getTestModule(), notNullValue()); }
@Override public Statement apply(Statement base, Description description) { wasRun = true; return super.apply(base, description); } };
@Test public void testInject() throws Exception { //GIVEN EntryPoint entryPoint = new EntryPoint(); //WHEN toothPickRule.inject(entryPoint); //THEN assertThat(entryPoint, notNullValue()); assertThat(entryPoint.dependency, notNullValue()); }
@Test(expected = IllegalStateException.class) public void testSetScopeName_shouldFail_whenScopeNameWasAlreadySet() throws Exception { toothPickRule.setScopeName("Bar"); }
@Test public void testGetInstance() throws Exception { //GIVEN //WHEN entryPoint = toothPickRule.getInstance(EntryPoint.class); //THEN assertThat(entryPoint, notNullValue()); assertThat(entryPoint.dependency, notNullValue()); }
@Test(expected = IllegalStateException.class) public void testSetScopeName_shouldFail_whenScopeNameAlreadyContainsATestModule() throws Exception { toothPickRuleWithoutScopeName.setScopeName("Foo"); }
@Test public void testMock() throws Exception { //GIVEN expect(dependency.num()).andReturn(2); replay(dependency); //WHEN entryPoint = toothPickRule.getInstance(EntryPoint.class); int num = entryPoint.dependency.num(); //THEN verify(dependency); assertThat(entryPoint, notNullValue()); assertThat(entryPoint.dependency, notNullValue()); assertThat(num, is(2)); }
public ToothPickRule(Object test, Object scopeName) { this.testModule = new ToothPickTestModule(test); if (scopeName != null) { setScopeName(scopeName); } }
public <T> T getInstance(Class<T> clazz) { return getInstance(clazz, null); }
@Test public void verifyInjectionAtOnCreate() { //GIVEN expect(mockContextNamer.getApplicationName()).andReturn("foo"); expect(mockContextNamer.getActivityName()).andReturn("bar"); replay(mockContextNamer); ActivityController<SimpleActivity> controllerSimpleActivity = Robolectric.buildActivity(SimpleActivity.class); SimpleActivity activity = controllerSimpleActivity.get(); toothPickRule.setScopeName(activity); //WHEN controllerSimpleActivity.create(); //THEN assertThat(activity.title.getText()).isEqualTo("foo"); assertThat(activity.subTitle.getText()).isEqualTo("bar"); verify(mockContextNamer); } }