本文整理汇总了Java中org.mockito.exceptions.base.MockitoAssertionError类的典型用法代码示例。如果您正苦于以下问题:Java MockitoAssertionError类的具体用法?Java MockitoAssertionError怎么用?Java MockitoAssertionError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockitoAssertionError类属于org.mockito.exceptions.base包,在下文中一共展示了MockitoAssertionError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: errorousVerificationOnPrivateMethodGivesFilteredErrorMessage
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Test
public void errorousVerificationOnPrivateMethodGivesFilteredErrorMessage() throws Exception {
PrivateMethodDemo tested = spy(new PrivateMethodDemo());
assertEquals("Hello Temp, you are 50 old.", tested.sayYear("Temp", 50));
when(tested, "doSayYear", Mockito.anyInt(), Mockito.anyString()).thenReturn("another");
assertEquals("another", tested.sayYear("Johan", 29));
assertEquals("another", tested.sayYear("test", 12));
try {
verifyPrivate(tested, never()).invoke("doSayYear", 50, "Temp");
fail("Should throw assertion error");
} catch (MockitoAssertionError e) {
assertEquals("\nsamples.privatemocking.PrivateMethodDemo.doSayYear(\n 50,\n \"Temp\"\n);\nNever wanted but invoked .", e
.getMessage());
}
}
示例2: errorousVerificationOfStaticMethodsGivesANonMockitoStandardMessage
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Test
public void errorousVerificationOfStaticMethodsGivesANonMockitoStandardMessage() throws Exception {
final String expected = "Hello world";
final String argument = "hello";
mockStatic(StaticService.class);
when(StaticService.say(argument)).thenReturn(expected);
assertEquals(expected, StaticService.say(argument));
// Verification is done in two steps using static methods.
verifyStatic(times(2));
try {
StaticService.say(argument);
fail("Should throw assertion error");
} catch (MockitoAssertionError e) {
assertEquals("\nsamples.singleton.StaticService.say(\"hello\");\nWanted 2 times but was 1 time.", e.getMessage());
}
}
示例3: verifyNoMoreInteractionsOnNewInstancesThrowsAssertionErrorWhenMoreInteractionsTookPlace
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Test
public void verifyNoMoreInteractionsOnNewInstancesThrowsAssertionErrorWhenMoreInteractionsTookPlace() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock = mock(MyClass.class);
whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock);
tested.simpleMultipleNew();
try {
verifyNoMoreInteractions(MyClass.class);
fail("Should throw exception!");
} catch (MockitoAssertionError e) {
assertTrue(e
.getMessage()
.startsWith(
"\nNo interactions wanted here:\n-> at samples.powermockito.junit4.verifynomoreinteractions.VerifyNoMoreInteractionsTest.verifyNoMoreInteractionsOnNewInstancesThrowsAssertionErrorWhenMoreInteractionsTookPlace(VerifyNoMoreInteractionsTest.java:"));
}
}
示例4: invoke
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
public Object invoke(Class<?> type, Object[] args, Class<?>[] sig) throws Exception {
Constructor<?> constructor = WhiteboxImpl.getConstructor(type, sig);
if (constructor.isVarArgs()) {
Object varArgs = args[args.length - 1];
final int varArgsLength = Array.getLength(varArgs);
Object[] oldArgs = args;
args = new Object[args.length + varArgsLength - 1];
System.arraycopy(oldArgs, 0, args, 0, oldArgs.length - 1);
for (int i = oldArgs.length - 1, j=0; i < args.length; i++, j++) {
args[i] = Array.get(varArgs, j);
}
}
try {
return substitute.performSubstitutionLogic(args);
} catch (MockitoAssertionError e) {
InvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(e, type);
}
// Won't happen
return null;
}
示例5: expect
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
public void expect(LifeCycle... lifeCycles){
long start = System.currentTimeMillis();
while(true) {
long elapse = System.currentTimeMillis() - start;
try {
doExpect(lifeCycles);
} catch (MockitoAssertionError mockitoAssertionError) {
if (elapse > wait_span) {
throw mockitoAssertionError;
} else {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
//Pass
break;
}
}
示例6: verify
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
public void verify(VerificationData data) {
int soFar = 0;
MockitoAssertionError error = null;
while (soFar <= timeout) {
try {
delegate.verify(data);
return;
} catch (MockitoAssertionError e) {
error = e;
soFar += treshhold;
sleep(treshhold);
}
}
if (error != null) {
throw error;
}
}
示例7: shouldWaitTheFullTimeIfTheTestCouldPass
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Test
public void shouldWaitTheFullTimeIfTheTestCouldPass() throws Exception {
// given
Thread t = waitAndExerciseMock(50);
// when
t.start();
// then
long startTime = System.currentTimeMillis();
try {
verify(mock, after(100).atLeast(2)).clear();
fail();
} catch (MockitoAssertionError e) {}
assertTrue(System.currentTimeMillis() - startTime >= 100);
}
示例8: verifyInOrder
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Override
public void verifyInOrder(VerificationDataInOrder data) {
Invocation firstUnverifiedInvocation = finder.findFirstUnverifiedInOrder(data.getOrderingContext(), data.getAllInvocations());
if (firstUnverifiedInvocation == null) {
Invocation previouslyVerified = finder.findPreviousVerifiedInOrder(data.getAllInvocations(), data.getOrderingContext());
new Reporter().wantedButNotInvokedInOrder(data.getWanted(), previouslyVerified);
}
if (!data.getWanted().matches(firstUnverifiedInvocation)) {
StringBuilder sb = new StringBuilder();
sb.append("Expected next invocation specified here: \n");
sb.append(data.getWanted().getLocation());
sb.append("\n");
sb.append("but next invocation was: \n");
sb.append(firstUnverifiedInvocation.getLocation());
sb.append("\n");
throw new MockitoAssertionError(sb.toString());
}
}
示例9: testFailureWhenInvocationNotPresent
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Test
public void testFailureWhenInvocationNotPresent() {
// given
foo.getFoo();
foo.getBaz();
// when
InOrder inOrder = Mockito.inOrder(foo);
inOrder.verify(foo).getFoo();
// then
try {
inOrder.verify(foo, immediatelyAfter()).getBar();
Assert.fail("should not verify");
} catch (MockitoAssertionError e) {
// happy path
}
}
示例10: testFailureWhenInvocationNotPresentCase2
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Test
public void testFailureWhenInvocationNotPresentCase2() {
// given
foo.getFoo();
// when
InOrder inOrder = Mockito.inOrder(foo);
inOrder.verify(foo).getFoo();
// then
try {
inOrder.verify(foo, immediatelyAfter()).getBar();
Assert.fail("should not verify");
} catch (MockitoAssertionError e) {
// happy path
}
}
示例11: testFailureOnWrongInvocationOrder
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Test
public void testFailureOnWrongInvocationOrder() {
// given
foo.getBar();
foo.getFoo();
// when
InOrder inOrder = Mockito.inOrder(foo);
inOrder.verify(foo).getFoo();
// then
try {
inOrder.verify(foo, immediatelyAfter()).getBar();
Assert.fail("should not verify");
} catch (MockitoAssertionError e) {
// happy path
}
}
示例12: testFailureWithIntermittentInvocations
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Test
public void testFailureWithIntermittentInvocations() {
// given
foo.getFoo();
foo.getBaz();
foo.getBar();
// when
InOrder inOrder = Mockito.inOrder(foo);
inOrder.verify(foo).getFoo();
// then
try {
inOrder.verify(foo, immediatelyAfter()).getBar();
Assert.fail("should not verify");
} catch (MockitoAssertionError e) {
// happy path
}
}
示例13: runTest
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
private void runTest(TestCase testCase) {
for (Harness harness : harnesses) {
try {
testCase.runTest(harness);
} catch (MockitoAssertionError e) {
throw new Error("Failed to get expected call on " + harness, e);
}
}
}
示例14: verifyNoMoreInteractionsOnMethodThrowsAssertionErrorWhenMoreInteractionsTookPlace
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Test
public void verifyNoMoreInteractionsOnMethodThrowsAssertionErrorWhenMoreInteractionsTookPlace() throws Exception {
mockStatic(StaticService.class);
assertNull(StaticService.say("hello"));
try {
verifyNoMoreInteractions(StaticService.class);
fail("Should throw exception!");
} catch (MockitoAssertionError e) {
assertTrue(e
.getMessage()
.startsWith(
"\nNo interactions wanted here:\n-> at samples.powermockito.junit4.verifynomoreinteractions.VerifyNoMoreInteractionsTest.verifyNoMoreInteractionsOnMethodThrowsAssertionErrorWhenMoreInteractionsTookPlace(VerifyNoMoreInteractionsTest.java"));
}
}
示例15: verifyNoMoreInteractions
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
public void verifyNoMoreInteractions() {
try {
Mockito.verifyNoMoreInteractions(substitute);
} catch (MockitoAssertionError e) {
InvocationControlAssertionError.updateErrorMessageForVerifyNoMoreInteractions(e);
throw e;
}
}