Java 类org.mockito.internal.stubbing.answers.ReturnsArgumentAt 实例源码

项目:eHMP    文件:InitOperationalDomainMessageHandlerTests.java   
@Before
public void setUp() throws Exception {
    mockJdsDao = mock(IGenericPOMObjectDAO.class);
    when(mockJdsDao.save(any(IPOMObject.class))).thenAnswer(new ReturnsArgumentAt(0));
    mockResourceLoader = mock(ResourceLoader.class);
    when(mockResourceLoader.getResource(anyString())).thenReturn(MOCK_RESOURCE);
    mockVistaOperationalDataService = mock(VistaOperationalDataDAO.class);
    when(mockVistaOperationalDataService.save(eq(MOCK_VISTA_ID), any(IPOMObject.class))).thenAnswer(new ReturnsArgumentAt(1));
    mockErrorDao = mock(IVprSyncErrorDao.class);

    handler = new InitOperationalDomainMessageHandler();
    handler.setJdsDao(mockJdsDao);
    handler.setResourceLoader(mockResourceLoader);
    handler.setVistaOperationalDataService(mockVistaOperationalDataService);
    handler.setErrorDao(mockErrorDao);
    converter = mock(SimpleMessageConverter.class);
    mockMessage = Mockito.mock(Message.class);
    mockSession = Mockito.mock(Session.class);
    handler.converter = converter;
}
项目:astor    文件:ReturnsArgumentAtTest.java   
@Test
public void should_raise_an_exception_if_index_is_not_in_allowed_range_at_creation_time() throws Throwable {
       try {
           new ReturnsArgumentAt(-30);
           fail();
       } catch (Exception e) {
           assertThat(e.getMessage())
                   .containsIgnoringCase("argument index")
                   .containsIgnoringCase("positive number")
                   .contains("1")
                   .containsIgnoringCase("last argument");
       }
   }
项目:astor    文件:ReturnsArgumentAtTest.java   
@Test
public void should_be_able_to_return_the_first_parameter() throws Throwable {
    assertThat(new ReturnsArgumentAt(0).answer(invocationWith("A", "B"))).isEqualTo("A");
}
项目:astor    文件:ReturnsArgumentAtTest.java   
@Test
public void should_be_able_to_return_the_second_parameter()
        throws Throwable {
    assertThat(new ReturnsArgumentAt(1).answer(invocationWith("A", "B", "C"))).isEqualTo("B");
}
项目:astor    文件:ReturnsArgumentAtTest.java   
@Test
public void should_be_able_to_return_the_last_parameter() throws Throwable {
    assertThat(new ReturnsArgumentAt(-1).answer(invocationWith("A"))).isEqualTo("A");
    assertThat(new ReturnsArgumentAt(-1).answer(invocationWith("A", "B"))).isEqualTo("B");
}
项目:astor    文件:ReturnsArgumentAtTest.java   
@Test
public void should_be_able_to_return_the_specified_parameter() throws Throwable {
    assertThat(new ReturnsArgumentAt(0).answer(invocationWith("A", "B", "C"))).isEqualTo("A");
    assertThat(new ReturnsArgumentAt(1).answer(invocationWith("A", "B", "C"))).isEqualTo("B");
    assertThat(new ReturnsArgumentAt(2).answer(invocationWith("A", "B", "C"))).isEqualTo("C");
}
项目:jinjava    文件:TruncateFilterTest.java   
@Before
public void setup() {
  when(interpreter.resolveString(anyString(), anyInt(), anyInt())).thenAnswer(new ReturnsArgumentAt(0));
}
项目:jinjava    文件:StripTagsFilterTest.java   
@Before
public void setup() {
  when(interpreter.renderFlat(anyString())).thenAnswer(new ReturnsArgumentAt(0));
}
项目:astor    文件:AdditionalAnswers.java   
/**
 * Returns the parameter of an invocation at the given position.
 *
 * <p>
 * This additional answer could be used at stub time using the
 * <code>then|do|will{@link org.mockito.stubbing.Answer}</code> methods. For example :
 * </p>
 *
 * <pre class="code"><code class="java">given(person.remember(dream1, dream2, dream3, dream4)).will(returnsArgAt(3));
 * doAnswer(returnsArgAt(3)).when(person).remember(dream1, dream2, dream3, dream4)</code></pre>
 *
 * @param <T> Return type of the invocation.
 * @return Answer that will return the second argument of the invocation.
 *
 * @since 1.9.5
 */
public static <T> Answer<T> returnsArgAt(int position) {
    return (Answer<T>) new ReturnsArgumentAt(position);
}