PowerMock & Java 11

After one year of no releases, things are really moving in PowerMock. PowerMock 2.0.0-RC1 was released. And with PowerMockito 2.0.0-RC1 + @PowerMockIgnore({“com.sun.org.apache.xerces.*”, “javax.xml.*”, “org.xml.*”, “org.w3c.*”}) The tests work under Java 11.

Mocking a method which returns Page interface

You can use a Mock reponse or an actual response and then use when, e.g.: Page<Company> companies = Mockito.mock(Page.class); Mockito.when(companyRepository.findAllByIsActiveTrue(pageable)).thenReturn(companies); Or, just instantiate the class: List<Company> companies = new ArrayList<>(); Page<Company> pagedResponse = new PageImpl(companies); Mockito.when(companyRepository.findAllByIsActiveTrue(pagedResponse)).thenReturn(pagedResponse);

Mockito: Mock private field initialization

Mockito comes with a helper class to save you some reflection boiler plate code: import org.mockito.internal.util.reflection.Whitebox; //… @Mock private Person mockedPerson; private Test underTest; // … @Test public void testMethod() { Whitebox.setInternalState(underTest, “person”, mockedPerson); // … } Update: Unfortunately the mockito team decided to remove the class in Mockito 2. So you are back to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)