Montag, 29. April 2019

Spring Security - get User Name

If you want to retrieve the name of  a logged in user, do this:

private String getUserName() {
    Object principal = SecurityContextHolder

    String userName;

    if (principal instanceof UserDetails) {
        userName = ((UserDetails)principal).getUsername();
    } else {
        userName = principal.toString();
    return userName;

Mittwoch, 24. April 2019

Recover and Restore System Properties with Java - JUnit and more - Free program

Sometimes it is necessary to change System Properties. Maybe for a Test or something else. This program and test will recover and restore the System Properties to their initial state.
The program and test may be used freely under GNU General Public License Version and is brought to you by Harder IT Consulting

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;


public void someTest() {



    assertThat(//your further asserts....


Dear Reader, This Blog is closed and remains as an archive. Please find our new Blog at