Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Batanov committed Feb 23, 2016
1 parent 220d3f8 commit 7ba972c
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import com.cloudbees.plugins.credentials.Credentials;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import hudson.EnvVars;
import hudson.ExtensionList;
import hudson.ProxyConfiguration;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Item;
import hudson.init.InitMilestone;
import hudson.model.*;
import hudson.plugins.git.Revision;
import hudson.plugins.git.util.Build;
import hudson.plugins.git.util.BuildData;
Expand All @@ -27,6 +28,8 @@
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -39,7 +42,6 @@

import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -50,13 +52,13 @@
import static org.mockito.Mockito.*;

@RunWith(PowerMockRunner.class)
@PrepareForTest({Secret.class, Jenkins.class, HttpClientBuilder.class})
@PrepareForTest({Secret.class, Jenkins.class, HttpClientBuilder.class, TokenMacro.class, Hudson.class, com.cloudbees.plugins.credentials.CredentialsProvider.class})
@PowerMockIgnore("javax.net.ssl.*")
public class StashNotifierTest
{
final static String sha1 = "1234567890123456789012345678901234567890";
private HttpClientBuilder httpClientBuilder;
private Jenkins jenkins;
private Hudson jenkins;

public StashNotifier buildStashNotifier(String stashBaseUrl) {
return new StashNotifier(
Expand All @@ -65,8 +67,8 @@ public StashNotifier buildStashNotifier(String stashBaseUrl) {
true,
null,
true,
null,
false,
"test-project",
true,
false);
}

Expand All @@ -75,13 +77,16 @@ public StashNotifier buildStashNotifier(String stashBaseUrl) {
AbstractBuild<?,?> build;

@Before
public void setUp() throws IOException, InterruptedException {
public void setUp() throws IOException, InterruptedException, MacroEvaluationException {
PowerMockito.mockStatic(Secret.class);
PowerMockito.mockStatic(Jenkins.class);
PowerMockito.mockStatic(HttpClientBuilder.class);
PowerMockito.mockStatic(TokenMacro.class);
PowerMockito.mockStatic(Hudson.class);
PowerMockito.mockStatic(com.cloudbees.plugins.credentials.CredentialsProvider.class);

buildListener = mock(BuildListener.class);
jenkins = mock(Jenkins.class);
jenkins = mock(Hudson.class);
build = mock(AbstractBuild.class);
AbstractProject project = mock(AbstractProject.class);
EnvVars environment = mock(EnvVars.class);
Expand All @@ -98,7 +103,9 @@ public void setUp() throws IOException, InterruptedException {
Build lastBuild = mock(Build.class);
List<BuildData> actions = Collections.singletonList(action);

when(Hudson.getInstance()).thenReturn(jenkins);
when(Jenkins.getInstance()).thenReturn(jenkins);
// when(jenkins.getExtensionList(anyObject().getClass())).thenReturn(Collections.emptyList());
when(jenkins.getRootUrl()).thenReturn("http://localhost/");
when(build.getEnvironment(buildListener)).thenReturn(environment);
when(action.getLastBuiltRevision()).thenReturn(revision);
Expand All @@ -121,7 +128,16 @@ public void setUp() throws IOException, InterruptedException {
action.lastBuild = lastBuild;
when(lastBuild.getMarked()).thenReturn(revision);

sn = buildStashNotifier("http://localhost");

when(TokenMacro.expandAll(build, buildListener, "test-project")).thenReturn("prepend-key");
when(com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
(Class)anyObject(),
(ItemGroup)anyObject(),
(Authentication)anyObject(),
(List<DomainRequirement>)anyList()
)).thenReturn(new ArrayList<Credentials>());

sn = buildStashNotifier("http://localhost");
}

@Test
Expand Down

0 comments on commit 7ba972c

Please sign in to comment.