Skip to content

Instantly share code, notes, and snippets.

@iamsurya-dev
Created February 6, 2018 16:46
Show Gist options
  • Save iamsurya-dev/a30993f0ab6fe83455776125f44c0f1c to your computer and use it in GitHub Desktop.
Save iamsurya-dev/a30993f0ab6fe83455776125f44c0f1c to your computer and use it in GitHub Desktop.
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest(PeopleUtil.class)
public class PeopleTest() {
private People people;
@Test
public void getNameTest() {
// Mock PeopleUtil class over here
PowerMockito.mockStatic(PeopleUtil.class);
PowerMockito.when(PeopleUtil.getPerson()).thenReturn("TestName");
people = new People();
Assert.assertEquals("TestName", people.getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment