use of org.mockito.exceptions.base.MockitoAssertionError in project curator by Netflix.
the class TestUtil method waitUntilVerified.
/**
* This waits until a mockito verification passed (which is provided in the runnable). This waits until the
* virification passed or the timeout has been reached. If the timeout has been reached this method will rethrow the
* {@link MockitoAssertionError} that comes from the mockito verification code.
*
* @param runnable
* The runnable containing the mockito verification.
* @param timeUnit
* The timeout timeunit.
* @param timeout
* The timeout.
* @throws InterruptedException
*/
public static void waitUntilVerified(Runnable runnable, TimeUnit timeUnit, int timeout) throws InterruptedException {
long startTime = System.currentTimeMillis();
do {
MockitoAssertionError exception = null;
try {
runnable.run();
} catch (MockitoAssertionError e) {
exception = e;
}
if (exception == null) {
return;
}
if (System.currentTimeMillis() > startTime + timeUnit.toMillis(timeout)) {
throw exception;
}
Thread.sleep(50);
} while (true);
}
use of org.mockito.exceptions.base.MockitoAssertionError in project powermock by powermock.
the class PrivateInstanceMockingTest method errorousVerificationOnPrivateMethodGivesFilteredErrorMessage.
@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());
}
}
use of org.mockito.exceptions.base.MockitoAssertionError in project powermock by powermock.
the class PrivateInstanceMockingTest method errorousVerificationOnPrivateMethodGivesFilteredErrorMessage.
@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());
}
}
use of org.mockito.exceptions.base.MockitoAssertionError in project powermock by powermock.
the class PrivateInstanceMockingTest method errorousVerificationOnPrivateMethodGivesFilteredErrorMessage.
@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());
}
}
use of org.mockito.exceptions.base.MockitoAssertionError in project powermock by powermock.
the class PrivateInstanceMockingTest method errorousVerificationOnPrivateMethodGivesFilteredErrorMessage.
@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());
}
}
Aggregations