本文整理汇总了Java中org.mockito.exceptions.base.MockitoAssertionError类的典型用法代码示例。如果您正苦于以下问题:Java MockitoAssertionError类的具体用法?Java MockitoAssertionError怎么用?Java MockitoAssertionError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockitoAssertionError类属于org.mockito.exceptions.base包,在下文中一共展示了MockitoAssertionError类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
}
开发者ID:awenblue,项目名称:powermock,代码行数:19,代码来源:PrivateInstanceMockingTest.java
示例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());
}
}
开发者ID:awenblue,项目名称:powermock,代码行数:21,代码来源:MockStaticTest.java
示例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:"));
}
}
开发者ID:awenblue,项目名称:powermock,代码行数:21,代码来源: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;
}
开发者ID:awenblue,项目名称:powermock,代码行数:22,代码来源:MockitoNewInvocationControl.java
示例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;
}
}
开发者ID:kejunxia,项目名称:AndroidMvc,代码行数:24,代码来源:LifeCycleValidator.java
示例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;
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:VerificationWithTimeoutImpl.java
示例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);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:VerificationAfterDelayTest.java
示例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());
}
}
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:23,代码来源:NoIntermediaryInvocation.java
示例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
}
}
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:19,代码来源:NoIntermediaryInvocationTest.java
示例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
}
}
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:18,代码来源:NoIntermediaryInvocationTest.java
示例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
}
}
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:19,代码来源:NoIntermediaryInvocationTest.java
示例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
}
}
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:20,代码来源:NoIntermediaryInvocationTest.java
示例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);
}
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:RequestManagerFragmentTest.java
示例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"));
}
}
开发者ID:awenblue,项目名称:powermock,代码行数:16,代码来源: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;
}
}
开发者ID:awenblue,项目名称:powermock,代码行数:9,代码来源:MockitoNewInvocationControl.java
示例16: invokeSubstitute
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
private void invokeSubstitute(Object... arguments) throws Exception {
try {
invocationControl.getSubstitute().performSubstitutionLogic(arguments);
} catch (MockitoAssertionError e) {
InvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(e, type);
}
}
开发者ID:awenblue,项目名称:powermock,代码行数:8,代码来源:DefaultConstructorArgumentsVerfication.java
示例17: shouldFailVerificationWithTimeout
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Test
public void shouldFailVerificationWithTimeout() throws Exception {
//given
Thread t = waitAndExerciseMock(40);
//when
t.start();
//then
verify(mock, never()).clear();
try {
verify(mock, timeout(20).atLeastOnce()).clear();
fail();
} catch (MockitoAssertionError e) {}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:16,代码来源:VerificationWithTimeoutTest.java
示例18: shouldVerifyAtMostXTimes
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Test
public void shouldVerifyAtMostXTimes() throws Exception {
mock.clear();
mock.clear();
verify(mock, atMost(2)).clear();
verify(mock, atMost(3)).clear();
try {
verify(mock, atMost(1)).clear();
fail();
} catch (MockitoAssertionError e) {}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:14,代码来源:AtMostXVerificationTest.java
示例19: shouldWorkWithArgumentMatchers
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Test
public void shouldWorkWithArgumentMatchers() throws Exception {
mock.add("one");
verify(mock, atMost(5)).add(anyString());
try {
verify(mock, atMost(0)).add(anyString());
fail();
} catch (MockitoAssertionError e) {}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:AtMostXVerificationTest.java
示例20: shouldPrintDecentMessage
import org.mockito.exceptions.base.MockitoAssertionError; //导入依赖的package包/类
@Test
public void shouldPrintDecentMessage() throws Exception {
mock.clear();
mock.clear();
try {
verify(mock, atMost(1)).clear();
fail();
} catch (MockitoAssertionError e) {
assertEquals("\nWanted at most 1 time but was 2", e.getMessage());
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:13,代码来源:AtMostXVerificationTest.java
注:本文中的org.mockito.exceptions.base.MockitoAssertionError类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论