Skip to content

Commit

Permalink
Merge pull request #380 from basil/refresh
Browse files Browse the repository at this point in the history
Upgrade plugin parent POM to latest version
  • Loading branch information
KostyaSha authored May 18, 2023
2 parents 7aa703e + cbedec7 commit ffdee80
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .mvn/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.4</version>
<version>1.6</version>
</extension>
</extensions>
27 changes: 2 additions & 25 deletions github-pullrequest-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
</scm>

<properties>
<mockito.version>3.12.4</mockito.version>
<powermock.version>2.0.9</powermock.version>
<excluded.tests>**/its/*.java</excluded.tests>
<access-modifier-checker.skip>true</access-modifier-checker.skip>
<spotbugs.skip>true</spotbugs.skip>
Expand All @@ -65,8 +63,8 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.346.x</artifactId>
<version>1763.v092b_8980a_f5e</version>
<artifactId>bom-2.361.x</artifactId>
<version>2081.v85885a_d2e5c5</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down Expand Up @@ -241,27 +239,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.coravy.hudson.plugins.github.GithubProjectProperty;
import com.coravy.hudson.plugins.github.GithubUrl;
import hudson.XmlFile;
import hudson.model.AbstractItem;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.ItemGroup;
Expand All @@ -15,9 +14,8 @@
import org.junit.runner.RunWith;
import org.kohsuke.github.GHRepository;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.MockedStatic;
import org.mockito.junit.MockitoJUnitRunner;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import java.io.File;
Expand All @@ -28,29 +26,26 @@

import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.jenkinsci.plugins.github.pullrequest.utils.JobHelper.ghPRTriggerFromJob;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

/**
* @author Alina_Karpovich
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({GithubProjectProperty.class, GithubUrl.class, JobHelper.class, AbstractItem.class,
GitHubPRTrigger.DescriptorImpl.class})
@RunWith(MockitoJUnitRunner.class)
public class GitHubPRRepositoryFactoryTest {
public static final String CONFIG_PATH = "src/test/resources";

@Mock
private GHRepository ghRepository;

@Mock
@Mock(lenient = true)
private ItemGroup parent;
@Mock
private Job job;
@Mock
@Mock(lenient = true)
private GitHubPRTrigger trigger;

@Mock
Expand All @@ -74,36 +69,37 @@ public void createForConfigFileIsBad() throws IOException, NoSuchFieldException,
@Test
public void createForNullTrigger() {
// when(job.getTrigger(GitHubPRTrigger.class)).thenReturn(null);
PowerMockito.mockStatic(JobHelper.class);
given(ghPRTriggerFromJob(job))
.willReturn(null);
try (MockedStatic<JobHelper> mockedStatic = mockStatic(JobHelper.class)) {
mockedStatic.when(() -> JobHelper.ghPRTriggerFromJob(job)).thenReturn(null);

Collection<? extends Action> repoCollection = new GitHubPRRepositoryFactory().createFor(job);
Assert.assertTrue(repoCollection instanceof List);
Assert.assertTrue(repoCollection.isEmpty());
}
}

@Test
public void shouldNotCreateRepoForTriggerWithExc() throws Exception {
// when(job.getTrigger(GitHubPRTrigger.class)).thenReturn(trigger);
PowerMockito.mockStatic(JobHelper.class);
given(ghPRTriggerFromJob(job))
.willReturn(trigger);
try (MockedStatic<JobHelper> mockedStatic = mockStatic(JobHelper.class)) {
mockedStatic.when(() -> JobHelper.ghPRTriggerFromJob(job)).thenReturn(trigger);

when(parent.getFullName()).thenReturn("mocked job");
// when(job.getParent()).thenReturn(parent);
when(trigger.getRepoFullName(job)).thenThrow(new RuntimeException());

assertThat(new GitHubPRRepositoryFactory().createFor(job), hasSize(0));
}
}

private void createForCommonTest(String filePath) throws IOException, NoSuchFieldException, IllegalAccessException {
PowerMockito.mockStatic(GitHubPRTrigger.DescriptorImpl.class);
given(GitHubPRTrigger.DescriptorImpl.get())
.willReturn(descriptor);
try (MockedStatic<GitHubPRTrigger.DescriptorImpl> staticGitHubPRTriggerDescriptor = mockStatic(GitHubPRTrigger.DescriptorImpl.class);
MockedStatic<JobHelper> staticJobHelper = mockStatic(JobHelper.class)) {
staticGitHubPRTriggerDescriptor.when(GitHubPRTrigger.DescriptorImpl::get).thenReturn(descriptor);

when(descriptor.isActualiseOnFactory()).thenReturn(false);

createForCommonExpectations(filePath, job, trigger);
createForCommonExpectations(filePath, job, trigger, staticJobHelper);

when(trigger.getRemoteRepository()).thenReturn(ghRepository);

Expand All @@ -113,6 +109,7 @@ private void createForCommonTest(String filePath) throws IOException, NoSuchFiel

Assert.assertEquals(job, trigger.getJob());
Assert.assertEquals(new File(filePath), configFile.getFile().getParentFile());
}
}

@CheckForNull
Expand All @@ -130,8 +127,8 @@ public static GitHubPRRepository getRepo(Collection<? extends Action> repoCollec
* @param job mock job.
* @param trigger mock trigger that is expected to be returned via job.getTrigger(GitHubPRTrigger.class).
*/
public static void createForCommonExpectations(AbstractProject<?, ?> job, GitHubPRTrigger trigger) {
createForCommonExpectations(CONFIG_PATH, job, trigger);
public static void createForCommonExpectations(Job job, GitHubPRTrigger trigger, MockedStatic<JobHelper> staticJobHelper) {
createForCommonExpectations(CONFIG_PATH, job, trigger, staticJobHelper);
}

/**
Expand All @@ -143,18 +140,17 @@ public static void createForCommonExpectations(AbstractProject<?, ?> job, GitHub
*/
public static void createForCommonExpectations(String filePath,
Job job,
GitHubPRTrigger trigger) {
GithubUrl githubUrl = PowerMockito.mock(GithubUrl.class);
GitHubPRTrigger trigger,
MockedStatic<JobHelper> staticJobHelper) {
GithubUrl githubUrl = mock(GithubUrl.class);
when(githubUrl.toString()).thenReturn("http://blaur");
GithubProjectProperty projectProperty = PowerMockito.mock(GithubProjectProperty.class);
GithubProjectProperty projectProperty = mock(GithubProjectProperty.class);

File file = new File(filePath);
when(job.getRootDir()).thenReturn(file);
when(job.getFullName()).thenReturn("jobFullName");

PowerMockito.mockStatic(JobHelper.class);
given(ghPRTriggerFromJob(job))
.willReturn(trigger);
staticJobHelper.when(() -> JobHelper.ghPRTriggerFromJob(job)).thenReturn(trigger);
when(trigger.getJob()).thenReturn(job);

when(trigger.getRepoFullName(job)).thenReturn(mock(GitHubRepositoryName.class));
Expand Down
Loading

0 comments on commit ffdee80

Please sign in to comment.