testing work

This commit is contained in:
eugenp 2015-08-26 12:10:06 +03:00
parent b7822cc678
commit 7a7ad7b368
1 changed files with 20 additions and 16 deletions

View File

@ -15,9 +15,10 @@ public class Java8EncodeDecodeTest {
// tests // tests
@Test @Test
public void whenStringIsEncoded() throws UnsupportedEncodingException { public void whenStringIsEncoded_thenOk() throws UnsupportedEncodingException {
final String originalInput = "test input"; final String originalInput = "test input";
final String encodedString = Base64.getEncoder().encodeToString(originalInput.getBytes()); final String encodedString = Base64.getEncoder().encodeToString(originalInput.getBytes());
assertNotNull(encodedString); assertNotNull(encodedString);
assertNotEquals(originalInput, encodedString); assertNotEquals(originalInput, encodedString);
} }
@ -35,9 +36,10 @@ public class Java8EncodeDecodeTest {
} }
@Test @Test
public void whenStringIsEncodedWithoutPadding() throws UnsupportedEncodingException { public void whenStringIsEncodedWithoutPadding_thenOk() throws UnsupportedEncodingException {
final String originalInput = "test input"; final String originalInput = "test input";
final String encodedString = Base64.getEncoder().withoutPadding().encodeToString(originalInput.getBytes()); final String encodedString = Base64.getEncoder().withoutPadding().encodeToString(originalInput.getBytes());
assertNotNull(encodedString); assertNotNull(encodedString);
assertNotEquals(originalInput, encodedString); assertNotEquals(originalInput, encodedString);
} }
@ -55,25 +57,27 @@ public class Java8EncodeDecodeTest {
} }
@Test @Test
public void whenURLIsEncoded() throws UnsupportedEncodingException { public void whenUrlIsEncoded_thenOk() throws UnsupportedEncodingException {
final String originalURL = "https://www.google.co.nz/?gfe_rd=cr&ei=dzbFVf&gws_rd=ssl#q=java"; 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 String encodedUrl = Base64.getUrlEncoder().encodeToString(originalUrl.getBytes());
assertNotNull(encodedURL); assertNotNull(encodedUrl);
assertNotEquals(originalURL, encodedURL); assertNotEquals(originalUrl, encodedUrl);
} }
@Test @Test
public void whenURLIsEncoded_thenURLCanBeDecoded() throws UnsupportedEncodingException { public void whenUrlIsEncoded_thenURLCanBeDecoded() throws UnsupportedEncodingException {
final String originalURL = "https://www.google.co.nz/?gfe_rd=cr&ei=dzbFVf&gws_rd=ssl#q=java"; 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 String encodedUrl = Base64.getUrlEncoder().encodeToString(originalUrl.getBytes());
final byte[] decodedBytes = Base64.getUrlDecoder().decode(encodedURL.getBytes());
final String decodedURL = new String(decodedBytes); final byte[] decodedBytes = Base64.getUrlDecoder().decode(encodedUrl.getBytes());
assertNotNull(decodedURL); final String decodedUrl = new String(decodedBytes);
assertEquals(originalURL, decodedURL);
assertNotNull(decodedUrl);
assertEquals(originalUrl, decodedUrl);
} }
@Test @Test
public void whenMIMEIsEncoded() throws UnsupportedEncodingException { public void whenMimeIsEncoded_thenOk() throws UnsupportedEncodingException {
final StringBuilder buffer = getMimeBuffer(); final StringBuilder buffer = getMimeBuffer();
final byte[] forEncode = buffer.toString().getBytes(); final byte[] forEncode = buffer.toString().getBytes();
@ -83,7 +87,7 @@ public class Java8EncodeDecodeTest {
} }
@Test @Test
public void whenMIMEIsEncoded_thenMIMECanBeDecoded() throws UnsupportedEncodingException { public void whenMimeIsEncoded_thenItCanBeDecoded() throws UnsupportedEncodingException {
final StringBuilder buffer = getMimeBuffer(); final StringBuilder buffer = getMimeBuffer();
final byte[] forEncode = buffer.toString().getBytes(); final byte[] forEncode = buffer.toString().getBytes();