Skip to content

Commit

Permalink
Merge pull request #335 from jglick/powermock
Browse files Browse the repository at this point in the history
Actually support PowerMock
  • Loading branch information
jglick authored Aug 3, 2020
2 parents 252ad76 + 61dd239 commit 3c7dc3e
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
target
work
*.class
build.log

# Mobile Tools for Java (J2ME)
.mtj.tmp/
Expand Down
7 changes: 7 additions & 0 deletions CONTRIBUTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ To run and build the repository with integration tests, you can execute

mvn clean verify

To run one IT:

[source,bash]
----
mvn verify -Dinvoker.test=powermock
----

## Building and using snapshots

Snapshots might be needed to provide reference implementations for Plugin POM patches.
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@
<artifactId>objenesis</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
1 change: 1 addition & 0 deletions src/it/powermock/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=-Dstyle.color=always -ntp clean install
42 changes: 42 additions & 0 deletions src/it/powermock/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>@project.version@</version>
<relativePath />
</parent>
<groupId>io.jenkins.plugins</groupId>
<artifactId>powermock</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>hpi</packaging>
<properties>
<jenkins.version>2.235.1</jenkins.version>
<java.level>8</java.level>
</properties>
<dependencies>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>
4 changes: 4 additions & 0 deletions src/it/powermock/src/main/resources/index.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
irrelevant
</div>
32 changes: 32 additions & 0 deletions src/it/powermock/src/test/java/test/XTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package test;

import jenkins.model.Jenkins;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest(Jenkins.class)
public class XTest {

@Mock
private Jenkins jenkins;

@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Jenkins.class);
PowerMockito.when(Jenkins.get()).thenReturn(jenkins);
PowerMockito.when(jenkins.getSystemMessage()).thenReturn("mocked");
}

@Test
public void smokes() {
assertEquals("mocked", Jenkins.get().getSystemMessage());
}

}

0 comments on commit 3c7dc3e

Please sign in to comment.