Skip to content

Commit

Permalink
Remove powermock usage (#2328)
Browse files Browse the repository at this point in the history
* remove powermock usage

Signed-off-by: Olivier Lamy <[email protected]>
  • Loading branch information
olamy authored Aug 29, 2022
1 parent de77554 commit 841710c
Show file tree
Hide file tree
Showing 42 changed files with 695 additions and 695 deletions.
6 changes: 5 additions & 1 deletion blueocean-bitbucket-pipeline/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@
<scope>test</scope>
</dependency>
<!-- end HttpRequest -->

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* @author Vivek Pandey
*/
public abstract class BitbucketWireMockBase extends PipelineBaseTest{
public abstract class BitbucketWireMockBase extends PipelineBaseTest {

// By default the wiremock tests will run without proxy
// The tests will use only the stubbed data and will fail if requests are made for missing data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.when;

import static org.mockito.Mockito.when;
public class HttpResponseTest {
@Test
public void testWithoutErrorDetails() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,16 @@
import io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbSaveContentResponse;
import io.jenkins.blueocean.blueocean_bitbucket_pipeline.model.BbUser;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.powermock.api.mockito.PowerMockito.when;

import static org.mockito.Mockito.when;
import static org.mockito.Mockito.mockStatic;
/**
* @author Vivek Pandey
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Secret.class})
@PowerMockIgnore({"javax.crypto.*", "javax.security.*", "javax.net.ssl.*", "com.sun.org.apache.xerces.*", "com.sun.org.apache.xalan.*", "javax.xml.*", "org.xml.*", "org.w3c.dom.*"})
public class BitbucketApiTest extends BbCloudWireMock {

private BitbucketApi api;
Expand Down Expand Up @@ -133,47 +126,49 @@ private StandardUsernamePasswordCredentials getMockedCredentials(final String us
final Secret secret = Mockito.mock(Secret.class);
when(secret.getPlainText()).thenReturn(getPassword());

PowerMockito.mockStatic(Secret.class);
when(Secret.toString(secret)).thenReturn(getPassword());

return new StandardUsernamePasswordCredentials() {
@Override
public CredentialsScope getScope() {
return CredentialsScope.SYSTEM;
}

@NonNull
@Override
public CredentialsDescriptor getDescriptor() {
return new CredentialsDescriptor() {

};
}

@NonNull
@Override
public String getUsername() {
return username;
}

@NonNull
@Override
public String getId() {
return "bitbucket-api-test";
}

@NonNull
@Override
public String getDescription() {
return "";
}

@NonNull
@Override
public Secret getPassword() {
return secret;
}
};
try (MockedStatic<Secret> secretMockedStatic = mockStatic(Secret.class)) {
when(Secret.toString(secret)).thenReturn(getPassword());

return new StandardUsernamePasswordCredentials() {
@Override
public CredentialsScope getScope() {
return CredentialsScope.SYSTEM;
}

@NonNull
@Override
public CredentialsDescriptor getDescriptor() {
return new CredentialsDescriptor() {

};
}

@NonNull
@Override
public String getUsername() {
return username;
}

@NonNull
@Override
public String getId() {
return "bitbucket-api-test";
}

@NonNull
@Override
public String getDescription() {
return "";
}

@NonNull
@Override
public Secret getPassword() {
return secret;
}
};
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,22 @@
import jenkins.branch.MultiBranchProject;
import net.sf.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.mockito.Mockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.Collections;

import static org.junit.Assert.*;
import static org.powermock.api.mockito.PowerMockito.*;

import static org.mockito.Mockito.when;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
/**
* @author Vivek Pandey
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Stapler.class})
@PowerMockIgnore({"javax.crypto.*", "javax.security.*", "javax.net.ssl.*", "com.sun.org.apache.xerces.*", "com.sun.org.apache.xalan.*", "javax.xml.*", "org.xml.*", "org.w3c.dom.*"})
public class BitbucketCloudScmContentProviderTest extends BbCloudWireMock {
@Test
public void getContent() throws UnirestException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,18 @@
import io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerBranch;
import io.jenkins.blueocean.commons.MapsHelper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.io.UnsupportedEncodingException;

import static org.junit.Assert.*;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.mockStatic;

/**
* @author Vivek Pandey
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Secret.class})
@PowerMockIgnore({"javax.crypto.*", "javax.security.*", "javax.net.ssl.*", "com.sun.org.apache.xerces.*", "com.sun.org.apache.xalan.*", "javax.xml.*", "org.xml.*", "org.w3c.dom.*"})
public class BitbucketApiTest extends BbServerWireMock {
private BitbucketApi api;

Expand Down Expand Up @@ -195,45 +189,46 @@ private StandardUsernamePasswordCredentials getMockedCredentials(){
final Secret secret = Mockito.mock(Secret.class);
when(secret.getPlainText()).thenReturn(getPassword());

PowerMockito.mockStatic(Secret.class);
when(Secret.toString(secret)).thenReturn(getPassword());

return new StandardUsernamePasswordCredentials(){
@Override
public CredentialsScope getScope() {
return CredentialsScope.SYSTEM;
}
@NonNull
@Override
public CredentialsDescriptor getDescriptor() {
return new CredentialsDescriptor(){

};
}
@NonNull
@Override
public String getUsername() {
return getUserName();
}

@NonNull
@Override
public String getId() {
return "bitbucket-api-test";
}

@NonNull
@Override
public String getDescription() {
return "";
}

@NonNull
@Override
public Secret getPassword() {
return secret;
}
};
try (MockedStatic<Secret> mockedStatic = mockStatic(Secret.class)) {
when(Secret.toString(secret)).thenReturn(getPassword());

return new StandardUsernamePasswordCredentials(){
@Override
public CredentialsScope getScope() {
return CredentialsScope.SYSTEM;
}
@NonNull
@Override
public CredentialsDescriptor getDescriptor() {
return new CredentialsDescriptor(){

};
}
@NonNull
@Override
public String getUsername() {
return getUserName();
}

@NonNull
@Override
public String getId() {
return "bitbucket-api-test";
}

@NonNull
@Override
public String getDescription() {
return "";
}

@NonNull
@Override
public Secret getPassword() {
return secret;
}
};
}
}

}
Loading

0 comments on commit 841710c

Please sign in to comment.