BAEL 1185 Lazy Verification with Mockito 2 mini-article accompanying code (#2985)

* BAEL-1185 Add Mockito2 lazy verification test

* Test multiple exceptions with lazy verification

* move mockito2 lazyVerificationTest to testing-modules

* update test method name in lazyverificationtest
This commit is contained in:
bahti 2017-11-14 14:17:57 +02:00 committed by Grzegorz Piwowarek
parent ebc5b52b3a
commit d6096fc58b
1 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,34 @@
package com.baeldung.mockito.java8;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.util.List;
import org.junit.Test;
import org.mockito.exceptions.base.MockitoAssertionError;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.VerificationCollector;
public class LazyVerificationTest {
@Test
public void whenLazilyVerified_thenReportsMultipleFailures() {
VerificationCollector collector = MockitoJUnit.collector()
.assertLazily();
List mockList = mock(List.class);
verify(mockList).add("one");
verify(mockList).clear();
try {
collector.collectAndReport();
} catch (MockitoAssertionError error) {
assertTrue(error.getMessage()
.contains("1. Wanted but not invoked:"));
assertTrue(error.getMessage()
.contains("2. Wanted but not invoked:"));
}
}
}