Java 类org.mockito.exceptions.verification.VerificationInOrderFailure 实例源码

项目:mockito-cookbook    文件:TaxUpdaterTestNgTest.java   
@Test
public void should_fail_at_updating_tax_factor_and_transfer_tax_in_specified_order_due_to_greedy_at_least() throws Exception {
    // given
    Person person = new Person();

    // when
    systemUnderTest.transferTaxFor(person);

    // then
    InOrder inOrder = Mockito.inOrder(taxService);
    inOrder.verify(taxService).updateTaxFactor(eq(person), anyDouble());
    inOrder.verify(taxService, atLeastOnce()).transferTaxFor(person);
    try {
        inOrder.verify(taxService).updateTaxFactor(eq(person), anyDouble());
        inOrder.verify(taxService).transferTaxFor(person);
    } catch (VerificationInOrderFailure verificationInOrderFailure) {}

}
项目:mockito-cookbook    文件:TaxUpdaterTestNgTest.java   
/** Expected added only for the test to pass **/
@Test(expectedExceptions = VerificationInOrderFailure.class)
public void should_fail_at_updating_second_tax_factor_in_specified_order_due_to_greedy_at_least() throws Exception {
    // given
    Person person = new Person();

    // when
    systemUnderTest.transferTaxFor(person);

    // then
    InOrder inOrder = Mockito.inOrder(taxService);
    inOrder.verify(taxService).updateTaxFactor(eq(person), anyDouble());
    inOrder.verify(taxService, atLeastOnce()).transferTaxFor(person);
    inOrder.verify(taxService).updateTaxFactor(eq(person), anyDouble());
    inOrder.verify(taxService).transferTaxFor(person);
}
项目:mockito-cookbook    文件:TaxUpdaterTest.java   
@Test
public void should_fail_at_updating_tax_factor_and_transfer_tax_in_specified_order_due_to_greedy_at_least() throws Exception {
    // given
    Person person = new Person();

    // when
    systemUnderTest.transferTaxFor(person);

    // then
    InOrder inOrder = Mockito.inOrder(taxService);
    inOrder.verify(taxService).updateTaxFactor(eq(person), anyDouble());
    inOrder.verify(taxService, atLeastOnce()).transferTaxFor(person);
    try {
        inOrder.verify(taxService).updateTaxFactor(eq(person), anyDouble());
        inOrder.verify(taxService).transferTaxFor(person);
    } catch (VerificationInOrderFailure verificationInOrderFailure) {}

}
项目:mockito-cookbook    文件:TaxUpdaterTest.java   
/** Expected added only for the test to pass **/
@Test(expected = VerificationInOrderFailure.class)
public void should_fail_at_updating_second_tax_factor_in_specified_order_due_to_greedy_at_least() throws Exception {
    // given
    Person person = new Person();

    // when
    systemUnderTest.transferTaxFor(person);

    // then
    InOrder inOrder = Mockito.inOrder(taxService);
    inOrder.verify(taxService).updateTaxFactor(eq(person), anyDouble());
    inOrder.verify(taxService, atLeastOnce()).transferTaxFor(person);
    inOrder.verify(taxService).updateTaxFactor(eq(person), anyDouble());
    inOrder.verify(taxService).transferTaxFor(person);
}
项目:astor    文件:DescriptiveMessagesOnVerificationInOrderErrorsTest.java   
@Test
public void shouldPrintMethodThatWasNotInvoked() {
    inOrder.verify(one).simpleMethod(1);
    inOrder.verify(one).simpleMethod(11);
    inOrder.verify(two, times(2)).simpleMethod(2);
    inOrder.verify(three).simpleMethod(3);
    try {
        inOrder.verify(three).simpleMethod(999);
        fail();
    } catch (VerificationInOrderFailure e) {
        String actualMessage = e.getMessage();
        String expectedMessage = 
                "\n" +
                "Verification in order failure" +
                "\n" +
                "Wanted but not invoked:" +
                "\n" +
                "iMethods.simpleMethod(999);"; 
        assertContains(expectedMessage, actualMessage);     
    }
}
项目:astor    文件:VerificationInOrderTest.java   
@Test
public void shouldVerifySingleMockInOrderAndNotInOrder() {
    mockOne = mock(IMethods.class);
    inOrder = inOrder(mockOne);

    mockOne.simpleMethod(1);
    mockOne.simpleMethod(2);

    verify(mockOne).simpleMethod(2);
    verify(mockOne).simpleMethod(1);

    inOrder.verify(mockOne).simpleMethod(2);
    try {
        inOrder.verify(mockOne).simpleMethod(1);
        fail();
    } catch (VerificationInOrderFailure e) {}
}
项目:astor    文件:VerificationInOrderTest.java   
@Test
public void shouldVerifyInOrderWhenTwoChunksAreEqual() {
    mockOne.simpleMethod();
    mockOne.simpleMethod();
    mockTwo.differentMethod();
    mockOne.simpleMethod();
    mockOne.simpleMethod();

    inOrder.verify(mockOne, times(2)).simpleMethod();
    inOrder.verify(mockTwo).differentMethod();
    inOrder.verify(mockOne, times(2)).simpleMethod();
    try {
        inOrder.verify(mockOne, atLeastOnce()).simpleMethod();
        fail();
    } catch (VerificationInOrderFailure e) {}
}
项目:astor    文件:VerificationInOrderTest.java   
@Test
public void shouldVerifyInOrderUsingMatcher() {
    mockOne.simpleMethod(1);
    mockOne.simpleMethod(2);
    mockTwo.differentMethod();
    mockOne.simpleMethod(3);
    mockOne.simpleMethod(4);

    verify(mockOne, times(4)).simpleMethod(anyInt());

    inOrder.verify(mockOne, times(2)).simpleMethod(anyInt());
    inOrder.verify(mockTwo).differentMethod();
    inOrder.verify(mockOne, times(2)).simpleMethod(anyInt());
    try {
        inOrder.verify(mockOne, times(3)).simpleMethod(anyInt());
        fail();
    } catch (VerificationInOrderFailure e) {}
}
项目:astor    文件:VerificationInOrderTest.java   
@Test
public void shouldVerifyInOrderWhenTwoChunksAreEqual() {
    mockOne.simpleMethod();
    mockOne.simpleMethod();
    mockTwo.differentMethod();
    mockOne.simpleMethod();
    mockOne.simpleMethod();

    inOrder.verify(mockOne, times(2)).simpleMethod();
    inOrder.verify(mockTwo).differentMethod();
    inOrder.verify(mockOne, times(2)).simpleMethod();
    try {
        inOrder.verify(mockOne, atLeastOnce()).simpleMethod();
        fail();
    } catch (VerificationInOrderFailure e) {}
}
项目:astor    文件:VerificationInOrderTest.java   
@Test
public void shouldVerifySingleMockInOrderAndNotInOrder() {
    mockOne = mock(IMethods.class);
    inOrder = inOrder(mockOne);

    mockOne.simpleMethod(1);
    mockOne.simpleMethod(2);

    verify(mockOne).simpleMethod(2);
    verify(mockOne).simpleMethod(1);

    inOrder.verify(mockOne).simpleMethod(2);
    try {
        inOrder.verify(mockOne).simpleMethod(1);
        fail();
    } catch (VerificationInOrderFailure e) {}
}
项目:fluent-bdd    文件:FluentMockitoTest.java   
@Test(expected = VerificationInOrderFailure.class)
public void inOrderFailure() {
    whenCalling(this::voidThing);
    thenVerify(dependency).someMethod("thing");
    andVerify(dependency).anotherMethod("bing");
    andVerify(anotherDependency).boringMethod();
}
项目:astor    文件:Reporter.java   
public void wantedButNotInvokedInOrder(PrintableInvocation wanted, PrintableInvocation previous) {
    throw new VerificationInOrderFailure(join(
                "Verification in order failure",
                "Wanted but not invoked:",
                wanted.toString(),
                new Location(),
                "Wanted anywhere AFTER following interaction:",
                previous.toString(),
                previous.getLocation(),
                ""
    ));
}
项目:astor    文件:Reporter.java   
public void tooLittleActualInvocationsInOrder(Discrepancy discrepancy, PrintableInvocation wanted, Location lastActualLocation) {
    String message = createTooLittleInvocationsMessage(discrepancy, wanted, lastActualLocation);

    throw new VerificationInOrderFailure(join(
            "Verification in order failure:" + message
            ));
}
项目:astor    文件:RelaxedVerificationInOrderTest.java   
@Test
public void shouldFailOnWrongMethodAfterLastInvocation() {
    inOrder.verify(mockOne).simpleMethod(4);
    try {
        inOrder.verify(mockOne).simpleMethod(999);
        fail();
    } catch (VerificationInOrderFailure e) {}
}
项目:astor    文件:StackTraceFilteringTest.java   
@Test
public void shouldFilterStacktraceWhenVerifyingInOrder() {
    InOrder inOrder = inOrder(mock);
    mock.oneArg(true);
    mock.oneArg(false);

    inOrder.verify(mock).oneArg(false);
    try {
        inOrder.verify(mock).oneArg(true);
        fail();
    } catch (VerificationInOrderFailure e) {
        assertThat(e, hasFirstMethodInStackTrace("shouldFilterStacktraceWhenVerifyingInOrder"));
    }
}
项目:astor    文件:PointingStackTraceToActualInvocationInOrderTest.java   
@Test
public void shouldPointStackTraceToPreviousVerified() {
    inOrder.verify(mock, atLeastOnce()).simpleMethod(anyInt());
    inOrder.verify(mockTwo).simpleMethod(anyInt());

    try {
        inOrder.verify(mock).simpleMethod(999);
        fail();
    } catch (VerificationInOrderFailure e) {
        assertContains("fourth(", e.getMessage());
    }
}
项目:astor    文件:PointingStackTraceToActualInvocationInOrderTest.java   
@Test
public void shouldPointToThirdMethod() {
    inOrder.verify(mock, atLeastOnce()).simpleMethod(anyInt());

    try {
        inOrder.verify(mockTwo).simpleMethod(999);
        fail();
    } catch (VerificationInOrderFailure e) {
        assertContains("third(", e.getMessage());
    }
}
项目:astor    文件:PointingStackTraceToActualInvocationInOrderTest.java   
@Test
public void shouldPointToFirstMethodBecauseOfTooManyActualInvocations() {
    try {
        inOrder.verify(mock, times(0)).simpleMethod(anyInt());
        fail();
    } catch (VerificationInOrderFailure e) {
        assertContains("first(", e.getMessage());
    }
}
项目:astor    文件:PointingStackTraceToActualInvocationInOrderTest.java   
@Test
public void shouldPointToSecondMethodBecauseOfTooManyActualInvocations() {
    inOrder.verify(mock).simpleMethod(anyInt());

    try {
        inOrder.verify(mockTwo, times(0)).simpleMethod(anyInt());
        fail();
    } catch (VerificationInOrderFailure e) {
        assertContains("second(", e.getMessage());
    }
}
项目:astor    文件:PointingStackTraceToActualInvocationInOrderTest.java   
@Test
public void shouldPointToFourthMethodBecauseOfTooLittleActualInvocations() {
    inOrder.verify(mock).simpleMethod(anyInt());
    inOrder.verify(mockTwo).simpleMethod(anyInt());
    inOrder.verify(mock).simpleMethod(anyInt());

    try {
        inOrder.verify(mockTwo, times(3)).simpleMethod(anyInt());
        fail();
    } catch (VerificationInOrderFailure e) {
        assertContains("fourth(", e.getMessage());
    }
}
项目:astor    文件:PointingStackTraceToActualInvocationChunkInOrderTest.java   
@Test
public void shouldPointStackTraceToPreviousInvocation() {
    inOrder.verify(mock, times(2)).simpleMethod(anyInt());
    inOrder.verify(mockTwo, times(2)).simpleMethod(anyInt());

    try {
        inOrder.verify(mock).simpleMethod(999);
        fail();
    } catch (VerificationInOrderFailure e) {
        assertContains("secondChunk(", e.getMessage());
    }
}
项目:astor    文件:PointingStackTraceToActualInvocationChunkInOrderTest.java   
@Test
public void shouldPointToThirdChunkWhenTooLittleActualInvocations() {
    inOrder.verify(mock, times(2)).simpleMethod(anyInt());
    inOrder.verify(mockTwo, times(2)).simpleMethod(anyInt());
    inOrder.verify(mock, atLeastOnce()).simpleMethod(anyInt());

    try {
        inOrder.verify(mockTwo, times(3)).simpleMethod(999);
        fail();
    } catch (VerificationInOrderFailure e) {
        assertContains("thirdChunk(", e.getMessage());
    }
}
项目:astor    文件:PointingStackTraceToActualInvocationChunkInOrderTest.java   
@Test
public void shouldPointToFourthChunkBecauseTooManyActualInvocations() {
    inOrder.verify(mock, atLeastOnce()).simpleMethod(anyInt());

    try {
        inOrder.verify(mockTwo, times(0)).simpleMethod(anyInt());
        fail();
    } catch (VerificationInOrderFailure e) {
        assertContains("fourthChunk(", e.getMessage());
    }
}
项目:astor    文件:FindingRedundantInvocationsInOrderTest.java   
@Test
public void shouldSayNoInteractionsWanted() throws Exception {
    //when
    mock.simpleMethod();

    //then
    InOrder inOrder = inOrder(mock);
    try {
        inOrder.verifyNoMoreInteractions();
        fail();
    } catch(VerificationInOrderFailure e) {
        assertContains("No interactions wanted", e.getMessage());
    }
}
项目:astor    文件:FindingRedundantInvocationsInOrderTest.java   
@Test
public void shouldFailToVerifyNoMoreInteractionsInOrder() throws Exception {
    //when
    mock.simpleMethod();
    mock.simpleMethod(10);
    mock.otherMethod();

    //then
    InOrder inOrder = inOrder(mock);
    inOrder.verify(mock).simpleMethod(10);
    try {
        inOrder.verifyNoMoreInteractions();
        fail();
    } catch(VerificationInOrderFailure e) {}
}
项目:astor    文件:FindingRedundantInvocationsInOrderTest.java   
@Test
public void shouldFailToVerifyNoMoreInteractionsInOrderWithMultipleMocks() throws Exception {
    //when
    mock.simpleMethod();
    mock2.simpleMethod();
    mock.otherMethod();

    //then
    InOrder inOrder = inOrder(mock, mock2);
    inOrder.verify(mock2).simpleMethod();
    try {
        inOrder.verifyNoMoreInteractions();
        fail();
    } catch(VerificationInOrderFailure e) {}
}
项目:astor    文件:BasicVerificationInOrderTest.java   
@Test
public void shouldFailOnSecondMethodBecauseFourInvocationsWanted() {
    inOrder.verify(mockOne, times(1)).simpleMethod(1);
    try {
        inOrder.verify(mockTwo, times(4)).simpleMethod(2);
        fail();
    } catch (VerificationInOrderFailure e) {
    }
}
项目:astor    文件:VerificationInOrderMixedWithOrdiraryVerificationTest.java   
@Test
public void shouldFailOnLastInvocationTooEarly() {
    inOrder.verify(mockThree).simpleMethod(4);

    verify(mockThree).simpleMethod(4);
    verify(mockTwo).simpleMethod(2);

    try {
        inOrder.verify(mockOne, atLeastOnce()).simpleMethod(1);
        fail();
    } catch (VerificationInOrderFailure e) {}
}
项目:astor    文件:BasicVerificationInOrderTest.java   
@Test
public void shouldFailOnLastMethodBecauseOneInvocationWanted() {
    inOrder.verify(mockOne, atLeastOnce()).simpleMethod(1);
    inOrder.verify(mockTwo, times(2)).simpleMethod(2);
    inOrder.verify(mockThree, atLeastOnce()).simpleMethod(3);
    inOrder.verify(mockTwo, atLeastOnce()).simpleMethod(2);
    try {
        inOrder.verify(mockOne, times(0)).simpleMethod(4);
        fail();
    } catch (VerificationInOrderFailure e) {
    }
}
项目:astor    文件:DescriptiveMessagesOnVerificationInOrderErrorsTest.java   
@Test
public void shouldNotSayArgumentsAreDifferent() {
    //this is the last invocation so any next verification in order should simply say wanted but not invoked
    inOrder.verify(three).simpleMethod(3);
    try {
        inOrder.verify(one).simpleMethod(999);
        fail();
    } catch (VerificationInOrderFailure e) {
        assertContains("Wanted but not invoked", e.getMessage());
    }
}
项目:astor    文件:DescriptiveMessagesOnVerificationInOrderErrorsTest.java   
@Test
public void shouldPrintTooManyInvocations() {
    inOrder.verify(one).simpleMethod(1);
    inOrder.verify(one).simpleMethod(11);
    try {
        inOrder.verify(two, times(1)).simpleMethod(2);
        fail();
    } catch (VerificationInOrderFailure e) {
        String actualMessage = e.getMessage();
        String expectedMessage = 
                "\n" +
                "Verification in order failure:" +
                "\n" +
                "iMethods.simpleMethod(2);" +
                "\n" +
                "Wanted 1 time:" +
                "\n" +
                "-> at"; 
        assertContains(expectedMessage, actualMessage);      

        String expectedCause =
            "\n" +
            "But was 2 times. Undesired invocation:" +
            "\n" +
            "-> at";
        assertContains(expectedCause, e.getMessage());
    }
}
项目:astor    文件:NumberOfInvocationsInOrderCheckerTest.java   
@Test
public void shouldReportTooManyInvocations() throws Exception {
    Invocation first = new InvocationBuilder().toInvocation();
    Invocation second = new InvocationBuilder().toInvocation();
    finderStub.validMatchingChunkToReturn.addAll(asList(first, second)); 

    try {
        checker.check(invocations, wanted, 1, context);
        fail();
    } catch (VerificationInOrderFailure e) {
        assertContains("Wanted 1 time", e.getMessage());
        assertContains("But was 2 times", e.getMessage());
    }
}
项目:astor    文件:SelectedMocksInOrderVerificationTest.java   
@Test
public void shouldFailVerificationForMockOne() {
    InOrder inOrder = inOrder(mockOne);

    inOrder.verify(mockOne).simpleMethod(1);
    try {
        inOrder.verify(mockOne).differentMethod();
        fail();
    } catch (VerificationInOrderFailure e) {}
}
项目:astor    文件:SelectedMocksInOrderVerificationTest.java   
@Test
public void shouldFailVerificationForMockOneBecauseOfWrongOrder() {
    InOrder inOrder = inOrder(mockOne);

    inOrder.verify(mockOne).simpleMethod(4);
    try {
        inOrder.verify(mockOne).simpleMethod(1);
        fail();
    } catch (VerificationInOrderFailure e) {}
}
项目:astor    文件:SelectedMocksInOrderVerificationTest.java   
@Test
public void shouldFailVerificationForMockTwo() {
    InOrder inOrder = inOrder(mockTwo);

    try {
        inOrder.verify(mockTwo).simpleMethod(2);
        fail();
    } catch (VerificationInOrderFailure e) {}
}
项目:astor    文件:SelectedMocksInOrderVerificationTest.java   
@Test
public void shouldThrowNoMoreInvocationsForMockTwo() {
    InOrder inOrder = inOrder(mockTwo);

    try {
        inOrder.verify(mockTwo, times(2)).simpleMethod(2);
        fail();
    } catch (VerificationInOrderFailure e) {}
}
项目:astor    文件:SelectedMocksInOrderVerificationTest.java   
@Test
public void shouldThrowTooLittleInvocationsForMockTwo() {
    InOrder inOrder = inOrder(mockTwo);

    try {
        inOrder.verify(mockTwo, times(4)).simpleMethod(2);
        fail();
    } catch (VerificationInOrderFailure e) {}
}
项目:astor    文件:SelectedMocksInOrderVerificationTest.java   
@Test
public void shouldThrowTooManyInvocationsForMockTwo() {
    InOrder inOrder = inOrder(mockTwo);

    try {
        inOrder.verify(mockTwo, times(2)).simpleMethod(2);
        fail();
    } catch (VerificationInOrderFailure e) {}
}
项目:astor    文件:BasicVerificationInOrderTest.java   
@Test
public void shouldFailWhenMiddleMethodVerifiedFirst() {
    inOrder.verify(mockTwo, times(2)).simpleMethod(2);
    try {
        inOrder.verify(mockOne).simpleMethod(1);
        fail();
    } catch (VerificationInOrderFailure e) {
    }
}
项目:astor    文件:RelaxedVerificationInOrderTest.java   
@Test
public void shouldFailTimesZeroInOrder() {
    inOrder.verify(mockTwo, times(2)).simpleMethod(2);
    try {
        inOrder.verify(mockThree, times(0)).simpleMethod(3);
        fail();
    } catch (VerificationInOrderFailure e) {}
}