Skip to content

Commit

Permalink
Merge pull request #9 from varyvol/JENKINS-42437v2
Browse files Browse the repository at this point in the history
[JENKINS-42437] Remove use of deprecated constructors in tests
  • Loading branch information
jglick committed Apr 13, 2017
2 parents aa86361 + 1f721a2 commit da51ba8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/test/java/org/jenkinsci/plugins/plaincredentials/BaseTest.java
Expand Up @@ -7,6 +7,7 @@
import java.util.Collections;
import java.util.List;

import com.cloudbees.plugins.credentials.SecretBytes;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl;
Expand Down Expand Up @@ -54,9 +55,25 @@ public void secretTextBaseTest() throws IOException {

@Test
public void secretFileBaseTest() throws IOException, URISyntaxException {
secretFileTest(false);
}

@Test
public void secretFileBaseTestWithDeprecatedCtor() throws IOException, URISyntaxException {
secretFileTest(true);
}

private void secretFileTest(boolean useDeprecatedConstructor) throws IOException, URISyntaxException {
DiskFileItem fileItem = createEmptyFileItem();

FileCredentialsImpl credential = new FileCredentialsImpl(CredentialsScope.GLOBAL, CRED_ID, "Test Secret file", fileItem, "keys.txt", Base64.encode(fileItem.get()).toString());

FileCredentialsImpl credential;

if (useDeprecatedConstructor) {
credential = new FileCredentialsImpl(CredentialsScope.GLOBAL, CRED_ID, "Test Secret file", fileItem, "keys.txt", Base64.encode(fileItem.get()).toString());
} else {
credential = new FileCredentialsImpl(CredentialsScope.GLOBAL, CRED_ID, "Test Secret file", fileItem, "keys.txt", SecretBytes.fromBytes(fileItem.get()));
}

FileCredentialsImpl updatedCredential = new FileCredentialsImpl(credential.getScope(), UPDATED_CRED_ID, credential.getDescription(), fileItem, credential.getFileName(), credential.getSecretBytes());
testCreateUpdateDelete(credential, updatedCredential);
}
Expand Down
Expand Up @@ -24,6 +24,7 @@
package org.jenkinsci.plugins.plaincredentials;

import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.SecretBytes;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemHeaders;
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl;
Expand All @@ -46,7 +47,7 @@ public class FileCredentialsTest {
@Test(expected = IllegalArgumentException.class)
@Issue("JENKINS-30926")
public void shouldThrowAnExceptionIfFileNameIsBlank() throws IOException {
new FileCredentialsImpl(CredentialsScope.GLOBAL, "1", "", new StubFileItem(), "", "");
new FileCredentialsImpl(CredentialsScope.GLOBAL, "1", "", new StubFileItem(), "", SecretBytes.fromString(""));
}

private class StubFileItem implements FileItem {
Expand Down

0 comments on commit da51ba8

Please sign in to comment.