/******************************************************************************************************************* * * Runs a {@link Task} associated with a the samples contexts. * * @param task the task * ******************************************************************************************************************/ public <V, T extends Throwable> V runWithContexts (@Nonnull Task<V, T> task) throws T { return contextManager.runWithContexts(contexts, task); } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ public ContextSampler (final @Nonnull Object owner) { contexts = Collections.unmodifiableList(contextManager.getContexts()); if (log.isTraceEnabled()) { log.trace(">>>> contexts for {} at construction time: {}", shortId(owner), shortIds(contexts)); } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "contextProvider") public void must_delegate_runWithContexts_to_ContextManager (final @Nonnull List<Object> contexts) { when(contextManager.getContexts()).thenReturn(contexts); // final Class<List<Object>> listClass = (Class)List.class; // final Class<Task<Object, RuntimeException>> taskClass = (Class)Task.class; // when(contextManager.<Object>runWithContexts(CoreMatchers.any(listClass), // CoreMatchers.any((taskClass)))); final Task<String, RuntimeException> task = mock(Task.class); fixture = new ContextSampler(new Object()); reset(contextManager); final Object result = fixture.runWithContexts(task); verify(contextManager, times(1)).runWithContexts(eq(contexts), same(task)); verifyNoMoreInteractions(contextManager); // assertThat(result, is((Object)"result")); FIXME: need to stub }
log.trace(">>>> contexts: {}", shortIds(contextManager.getContexts())); context = contextManager.findContextOfType(contextType);
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "ownersAndRoleImplementations") public void must_correctly_find_roles (final @Nonnull Object owner, final @Nonnull Class<?> roleClass, final @Nonnull List<?> expectedRoles) throws NotFoundException { // given when(contextManager.findContextOfType(eq(Context1.class))).thenThrow(new NotFoundException()); when(contextManager.findContextOfType(eq(Context2.class))).thenReturn(context2); final UnderTest underTest = new UnderTest(); registerMockRoles(underTest); underTest.registerBean(bean1); underTest.registerBean(bean2); underTest.scan(asList(RI1A.class, RI1B.class, RI1C.class, RI2A.class, RI2B.class, RI2C.class, RI3A.class, RI3B.class, RI3C.class)); // when final List<?> actualRoles = underTest.findRoles(owner, roleClass); // then final String s = String.format("owner: %s role: %s", shortId(owner), shortName(roleClass)); assertListEquals(s, actualRoles, expectedRoles); }
final @Nonnull TupleQueryResult queryResult) return contextManager.runWithContexts(getContexts(), new Task<List<E>, RuntimeException>()
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "contextProvider") public void must_sample_Contexts_at_construction_time (final @Nonnull List<Object> contexts) { when(contextManager.getContexts()).thenReturn(contexts); fixture = new ContextSampler(new Object()); assertThat(fixture.getContexts(), is(contexts)); }