org.mockito.internal.stubbing.answers.ReturnsArgumentAt Java Examples

The following examples show how to use org.mockito.internal.stubbing.answers.ReturnsArgumentAt. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AMQPObservableQueueTest.java    From conductor with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	configuration = Mockito.mock(Configuration.class);
	Answer answer = new ReturnsArgumentAt(1);
	when(configuration.getProperty(Mockito.anyString(), Mockito.anyString())).thenAnswer(answer);
	when(configuration.getBooleanProperty(Mockito.anyString(), Mockito.anyBoolean())).thenAnswer(answer);
	when(configuration.getIntProperty(Mockito.anyString(), anyInt())).thenAnswer(answer);
	addresses = new Address[] { new Address("localhost", AMQP.PROTOCOL.PORT) };
}
 
Example #2
Source File: ReturnsArgumentAtTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@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");
       }
   }
 
Example #3
Source File: ReturnsArgumentAtTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void should_be_able_to_return_the_first_parameter() throws Throwable {
	assertThat(new ReturnsArgumentAt(0).answer(invocationWith("A", "B"))).isEqualTo("A");
}
 
Example #4
Source File: ReturnsArgumentAtTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void should_be_able_to_return_the_second_parameter()
		throws Throwable {
	assertThat(new ReturnsArgumentAt(1).answer(invocationWith("A", "B", "C"))).isEqualTo("B");
}
 
Example #5
Source File: ReturnsArgumentAtTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@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");
}
 
Example #6
Source File: ReturnsArgumentAtTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@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");
}
 
Example #7
Source File: StripTagsFilterTest.java    From jinjava with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
  when(interpreter.renderFlat(anyString())).thenAnswer(new ReturnsArgumentAt(0));
}
 
Example #8
Source File: AdditionalAnswers.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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);
}