Posts mit dem Label static werden angezeigt. Alle Posts anzeigen
Posts mit dem Label static werden angezeigt. Alle Posts anzeigen

Montag, 17. Juni 2019

Intellij Order Of Imports

IntelliJ sometimes changes the appearance of imports in the code on checkout when organizing imports.

To control that, one can adjust the settings:

Settings -> Editor -> Code Style -> Java -> Layout static imports separately

Change the order as you need, IntelliJ will sort the imports accordingly.

Mittwoch, 17. April 2019

Mock static methods with Mockito in Java (mock, static, method, java)


import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.BDDMockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;


@RunWith(PowerMockRunner.class)
@PrepareForTest(MyStatic.class)
...


@Test
public void someTest() {
    
    //given    
    PowerMockito.mockStatic(MyStatic.class);
    BDDMockito.given(MyStatic.someStaticMethod()).willReturn(...);

    //when
    ...

    //then     
    PowerMockito.verifyStatic();
    MyStatic.someStaticMethod();

    assertThat(//your further asserts....

NEW BLOG! http://cleancode.consulting/

Dear Reader, This Blog is closed and remains as an archive. Please find our new Blog at  http://cleancode.consulting/