Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Remove any @Test(expected=SomeException.class) and use:

    Code Block
    org.junit.jupiter.api.Assertions.assertThrowassertThrows(SomeException.class, ()-> { /* Your code here */ });


  • Replace the org.junit.runner.RunWith annotation with the org.junit.jupiter.api.extension.ExtendWith, for example:

    Code Block
    @ExtendsWith@ExtendWith(SpringExtension.class)
    public class SomeIntegrationTest {}
    
    @ExtendsWith@ExtendWith(MockitoExtension.class)
    public class SomeUnitTest {}


  • If the tests fails with UnnecessaryStubbingException you might need to review your test code (E.g. Check that unnecessary stubbing is not performed in a @BeforeEach, for example stubbing that is not used in all the tests). If it's not possible to fix an old test without spending too much time use the org.mockito.Mockito.lenient() or enable the lenient setting at the class level:

    Code Block
    @ExtendsWith@ExtendWith(MockitoExtension.class)
    @MockitoSettings(strictness = Strictness.LENIENT)
    public class SomeLenientTest {}


  • For mocks where the mocked object is NOT STATEFUL and the return value of the method is NOT specific to ANY PARAMETERS, use Mockitio.lenient().when() to make that specific mock lenient. Do this only in the @BeforeEach setup() method.

    Code Block
    	@BeforeEach
    	public void setup(){
    		lenient().when(mockServiceProvider.getTableServices()).thenReturn(mockTableService);
    		lenient().when(mockServiceProvider.getWikiService()).thenReturn(mockWikiService);
    		lenient().when(mockServiceProvider.getEntityService()).thenReturn(mockEntityService);
    		lenient().when(mockServiceProvider.getDoiServiceV2()).thenReturn(mockDoiServiceV2);
    		lenient().when(mockServiceProvider.getDiscussionService()).thenReturn(mockDiscussionService);
    		lenient().when(mockServiceProvider.getDataAccessService()).thenReturn(mockDataAccessService);
    	}


...