Created
June 11, 2013 08:25
-
-
Save jpbriend/5755273 to your computer and use it in GitHub Desktop.
Unit Tests with Powermock and Fest-Assert 1.x. Using mockStatic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
... | |
<dependency> | |
<groupId>org.powermock</groupId> | |
<artifactId>powermock-core</artifactId> | |
<version>1.4.11</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.powermock</groupId> | |
<artifactId>powermock-module-junit4</artifactId> | |
<version>1.4.11</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.powermock</groupId> | |
<artifactId>powermock-api-mockito</artifactId> | |
<version>1.4.11</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.easytesting</groupId> | |
<artifactId>fest-assert</artifactId> | |
<version>1.4</version> | |
<scope>test</scope> | |
</dependency> | |
... | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(PowerMockRunner.class) | |
@PrepareForTest(StaticTokenUtils.class) | |
@PowerMockIgnore({ "org.xml.*", "javax.xml.*" }) | |
public class UnitTest { | |
... | |
... | |
@Mock | |
private AppliDAO appliDAO; | |
@InjectMocks | |
private AppliServiceImpl tested = new AppliServiceImpl(); | |
@Before | |
public void setUp() { | |
PowerMockito.mockStatic(StaticTokenUtils.class); | |
when(StaticTokenUtils.someStaticMethod()).thenReturn("someResult"); | |
} | |
@Test | |
public void testMethod() throws Exception { | |
when(...).thenReturn(...); | |
Object result = tested.method("someParameter"); | |
assertThat(result).isNotNull(); | |
verify(...)...(); | |
verifyStatic(StaticTokenUtils.class); | |
StaticTokenUtils.someStaticMethod(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment