Created
November 1, 2015 18:27
-
-
Save ihommani/b122e6fa67948404db45 to your computer and use it in GitHub Desktop.
Typical test using tesng with mockito
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SharePointStreamFetcherTest { | |
| @Mock(answer = Answers.RETURNS_DEEP_STUBS) | |
| SPDataLoaderManager spDataLoaderManager; | |
| SharePointStreamFetcher underTest; | |
| SoftAssertions softAssertions = new SoftAssertions(); | |
| @BeforeMethod | |
| public void setUp() throws Exception { | |
| MockitoAnnotations.initMocks(spDataLoaderManager); | |
| underTest = new SharePointStreamFetcher(spDataLoaderManager, "siteUrl", "listId"); | |
| } | |
| @AfterMethod | |
| public void tearDown() throws Exception { | |
| softAssertions.assertAll(); | |
| // specifick mock to forget each previous stubbing. | |
| reset(spDataLoaderManager); | |
| } | |
| @Test | |
| public void should_do_some_testing() throws IOException, JAXBException { | |
| // given | |
| ItemIndex itemIndex = new ItemIndex(); | |
| // ... setting some stuff | |
| when(spDataLoaderManager.getItemIndex(anyString(), anyString(), anyInt(), anyString())).thenReturn(itemIndex); | |
| // when | |
| Stream<ItemIndex> itemIndexStream = underTest.getItemIndexStream(); | |
| List<ItemIndex> toTestValue = itemIndexStream.collect(Collectors.toList()); | |
| // then | |
| softAssertions.assertThat(toTestValue).isNotEmpty().hasSize(42).contains(new ItemIndex()); | |
| verify(spDataLoaderManager, atLeastOnce()).getItemIndex(anyString(), anyString(), anyInt(), anyString()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment