test cleanup
This commit is contained in:
parent
6b10bee0a0
commit
ed2b7e4e2f
|
@ -11,11 +11,13 @@ import org.junit.Test;
|
|||
|
||||
public class ApacheCommonsEncodeDecodeTest {
|
||||
|
||||
// tests
|
||||
|
||||
@Test
|
||||
public void whenStringIsEncoded() throws UnsupportedEncodingException {
|
||||
String originalInput = "test input";
|
||||
Base64 base64 = new Base64();
|
||||
String encodedString = new String(base64.encode(originalInput.getBytes()));
|
||||
final String originalInput = "test input";
|
||||
final Base64 base64 = new Base64();
|
||||
final String encodedString = new String(base64.encode(originalInput.getBytes()));
|
||||
|
||||
assertNotNull(encodedString);
|
||||
assertNotEquals(originalInput, encodedString);
|
||||
|
@ -23,11 +25,11 @@ public class ApacheCommonsEncodeDecodeTest {
|
|||
|
||||
@Test
|
||||
public void whenStringIsEncoded_thenStringCanBeDecoded() throws UnsupportedEncodingException {
|
||||
String originalInput = "test input";
|
||||
Base64 base64 = new Base64();
|
||||
String encodedString = new String(base64.encode(originalInput.getBytes()));
|
||||
final String originalInput = "test input";
|
||||
final Base64 base64 = new Base64();
|
||||
final String encodedString = new String(base64.encode(originalInput.getBytes()));
|
||||
|
||||
String decodedString = new String(base64.decode(encodedString.getBytes()));
|
||||
final String decodedString = new String(base64.decode(encodedString.getBytes()));
|
||||
|
||||
assertNotNull(decodedString);
|
||||
assertEquals(originalInput, decodedString);
|
||||
|
@ -35,8 +37,8 @@ public class ApacheCommonsEncodeDecodeTest {
|
|||
|
||||
@Test
|
||||
public void whenStringIsEncodedUsingStaticMethod() throws UnsupportedEncodingException {
|
||||
String originalInput = "test input";
|
||||
String encodedString = new String(Base64.encodeBase64(originalInput.getBytes()));
|
||||
final String originalInput = "test input";
|
||||
final String encodedString = new String(Base64.encodeBase64(originalInput.getBytes()));
|
||||
|
||||
assertNotNull(encodedString);
|
||||
assertNotEquals(originalInput, encodedString);
|
||||
|
@ -44,10 +46,10 @@ public class ApacheCommonsEncodeDecodeTest {
|
|||
|
||||
@Test
|
||||
public void whenStringIsEncodedUsingStaticMethod_thenStringCanBeDecodedUsingStaticMethod() throws UnsupportedEncodingException {
|
||||
String originalInput = "test input";
|
||||
String encodedString = new String(Base64.encodeBase64(originalInput.getBytes()));
|
||||
final String originalInput = "test input";
|
||||
final String encodedString = new String(Base64.encodeBase64(originalInput.getBytes()));
|
||||
|
||||
String decodedString = new String(Base64.decodeBase64(encodedString.getBytes()));
|
||||
final String decodedString = new String(Base64.decodeBase64(encodedString.getBytes()));
|
||||
|
||||
assertNotNull(decodedString);
|
||||
assertEquals(originalInput, decodedString);
|
||||
|
|
|
@ -12,91 +12,94 @@ import org.junit.Test;
|
|||
|
||||
public class Java8EncodeDecodeTest {
|
||||
|
||||
// tests
|
||||
|
||||
@Test
|
||||
public void whenStringIsEncoded() throws UnsupportedEncodingException {
|
||||
String originalInput = "test input";
|
||||
String encodedString = Base64.getEncoder().encodeToString(originalInput.getBytes());
|
||||
final String originalInput = "test input";
|
||||
final String encodedString = Base64.getEncoder().encodeToString(originalInput.getBytes());
|
||||
assertNotNull(encodedString);
|
||||
assertNotEquals(originalInput, encodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStringIsEncoded_thenStringCanBeDecoded() throws UnsupportedEncodingException {
|
||||
String originalInput = "test input";
|
||||
String encodedString = Base64.getEncoder().encodeToString(originalInput.getBytes());
|
||||
final String originalInput = "test input";
|
||||
final String encodedString = Base64.getEncoder().encodeToString(originalInput.getBytes());
|
||||
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
|
||||
String decodedString = new String(decodedBytes);
|
||||
final byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
|
||||
final String decodedString = new String(decodedBytes);
|
||||
|
||||
assertNotNull(decodedString);
|
||||
assertEquals(originalInput, decodedString);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenStringIsEncodedWithoutPadding() throws UnsupportedEncodingException {
|
||||
String originalInput = "test input";
|
||||
String encodedString = Base64.getEncoder().withoutPadding().encodeToString(originalInput.getBytes());
|
||||
final String originalInput = "test input";
|
||||
final String encodedString = Base64.getEncoder().withoutPadding().encodeToString(originalInput.getBytes());
|
||||
assertNotNull(encodedString);
|
||||
assertNotEquals(originalInput, encodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenStringIsEncodedWithoutPadding_thenStringCanBeDecoded() throws UnsupportedEncodingException {
|
||||
String originalInput = "test input";
|
||||
String encodedString = Base64.getEncoder().withoutPadding().encodeToString(originalInput.getBytes());
|
||||
final String originalInput = "test input";
|
||||
final String encodedString = Base64.getEncoder().withoutPadding().encodeToString(originalInput.getBytes());
|
||||
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
|
||||
String decodedString = new String(decodedBytes);
|
||||
final byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
|
||||
final String decodedString = new String(decodedBytes);
|
||||
|
||||
assertNotNull(decodedString);
|
||||
assertEquals(originalInput, decodedString);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenURLIsEncoded() throws UnsupportedEncodingException {
|
||||
String originalURL = "https://www.google.co.nz/?gfe_rd=cr&ei=dzbFVf&gws_rd=ssl#q=java";
|
||||
String encodedURL = Base64.getUrlEncoder().encodeToString(originalURL.getBytes());
|
||||
final String originalURL = "https://www.google.co.nz/?gfe_rd=cr&ei=dzbFVf&gws_rd=ssl#q=java";
|
||||
final String encodedURL = Base64.getUrlEncoder().encodeToString(originalURL.getBytes());
|
||||
assertNotNull(encodedURL);
|
||||
assertNotEquals(originalURL, encodedURL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenURLIsEncoded_thenURLCanBeDecoded() throws UnsupportedEncodingException {
|
||||
String originalURL = "https://www.google.co.nz/?gfe_rd=cr&ei=dzbFVf&gws_rd=ssl#q=java";
|
||||
String encodedURL = Base64.getUrlEncoder().encodeToString(originalURL.getBytes());
|
||||
byte[] decodedBytes = Base64.getUrlDecoder().decode(encodedURL.getBytes());
|
||||
String decodedURL = new String(decodedBytes);
|
||||
final String originalURL = "https://www.google.co.nz/?gfe_rd=cr&ei=dzbFVf&gws_rd=ssl#q=java";
|
||||
final String encodedURL = Base64.getUrlEncoder().encodeToString(originalURL.getBytes());
|
||||
final byte[] decodedBytes = Base64.getUrlDecoder().decode(encodedURL.getBytes());
|
||||
final String decodedURL = new String(decodedBytes);
|
||||
assertNotNull(decodedURL);
|
||||
assertEquals(originalURL, decodedURL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenMIMEIsEncoded() throws UnsupportedEncodingException {
|
||||
StringBuilder buffer = getMimeBuffer();
|
||||
final StringBuilder buffer = getMimeBuffer();
|
||||
|
||||
byte[] forEncode = buffer.toString().getBytes();
|
||||
String encodedMime = Base64.getMimeEncoder().encodeToString(forEncode);
|
||||
final byte[] forEncode = buffer.toString().getBytes();
|
||||
final String encodedMime = Base64.getMimeEncoder().encodeToString(forEncode);
|
||||
|
||||
assertNotNull(encodedMime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenMIMEIsEncoded_thenMIMECanBeDecoded() throws UnsupportedEncodingException {
|
||||
StringBuilder buffer = getMimeBuffer();
|
||||
final StringBuilder buffer = getMimeBuffer();
|
||||
|
||||
byte[] forEncode = buffer.toString().getBytes();
|
||||
String encodedMime = Base64.getMimeEncoder().encodeToString(forEncode);
|
||||
final byte[] forEncode = buffer.toString().getBytes();
|
||||
final String encodedMime = Base64.getMimeEncoder().encodeToString(forEncode);
|
||||
|
||||
byte[] decodedBytes = Base64.getMimeDecoder().decode(encodedMime);
|
||||
String decodedMime = new String(decodedBytes);
|
||||
final byte[] decodedBytes = Base64.getMimeDecoder().decode(encodedMime);
|
||||
final String decodedMime = new String(decodedBytes);
|
||||
assertNotNull(decodedMime);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
private static StringBuilder getMimeBuffer() {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
for (int count = 0; count < 10; ++count) {
|
||||
buffer.append(UUID.randomUUID().toString());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue