This repository has been archived by the owner on Mar 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/test/java/co/lqnt/lockbox/cipher/exception/CipherFinalizedExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* This file is part of the Lockbox package. | ||
* | ||
* Copyright © 2014 Erin Millard | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
package co.lqnt.lockbox.cipher.exception; | ||
|
||
import co.lqnt.lockbox.cipher.CipherInterface; | ||
import co.lqnt.lockbox.cipher.EncryptCipher; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class CipherFinalizedExceptionTest | ||
{ | ||
public CipherFinalizedExceptionTest() | ||
{ | ||
this.cipher = new EncryptCipher(); | ||
} | ||
|
||
@Test | ||
public void testException() | ||
{ | ||
Exception cause = new Exception(); | ||
CipherFinalizedException exception = new CipherFinalizedException(this.cipher, cause); | ||
|
||
Assert.assertSame(this.cipher, exception.cipher()); | ||
Assert.assertEquals(exception.getMessage(), "The cipher is already finalized."); | ||
Assert.assertSame(exception.getCause(), cause); | ||
} | ||
|
||
@Test | ||
public void testExceptionWithoutCause() | ||
{ | ||
CipherFinalizedException exception = new CipherFinalizedException(this.cipher); | ||
|
||
Assert.assertSame(this.cipher, exception.cipher()); | ||
Assert.assertEquals(exception.getMessage(), "The cipher is already finalized."); | ||
Assert.assertNull(exception.getCause()); | ||
} | ||
|
||
private CipherInterface cipher; | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/co/lqnt/lockbox/cipher/exception/CipherNotInitializedExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* This file is part of the Lockbox package. | ||
* | ||
* Copyright © 2014 Erin Millard | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
package co.lqnt.lockbox.cipher.exception; | ||
|
||
import co.lqnt.lockbox.cipher.CipherInterface; | ||
import co.lqnt.lockbox.cipher.EncryptCipher; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class CipherNotInitializedExceptionTest | ||
{ | ||
public CipherNotInitializedExceptionTest() | ||
{ | ||
this.cipher = new EncryptCipher(); | ||
} | ||
|
||
@Test | ||
public void testException() | ||
{ | ||
Exception cause = new Exception(); | ||
CipherNotInitializedException exception = new CipherNotInitializedException(this.cipher, cause); | ||
|
||
Assert.assertSame(this.cipher, exception.cipher()); | ||
Assert.assertEquals(exception.getMessage(), "The cipher is not initialized."); | ||
Assert.assertSame(exception.getCause(), cause); | ||
} | ||
|
||
@Test | ||
public void testExceptionWithoutCause() | ||
{ | ||
CipherNotInitializedException exception = new CipherNotInitializedException(this.cipher); | ||
|
||
Assert.assertSame(this.cipher, exception.cipher()); | ||
Assert.assertEquals(exception.getMessage(), "The cipher is not initialized."); | ||
Assert.assertNull(exception.getCause()); | ||
} | ||
|
||
private CipherInterface cipher; | ||
} |
71 changes: 71 additions & 0 deletions
71
src/test/java/co/lqnt/lockbox/cipher/exception/UnsupportedCipherParametersExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* This file is part of the Lockbox package. | ||
* | ||
* Copyright © 2014 Erin Millard | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
package co.lqnt.lockbox.cipher.exception; | ||
|
||
import co.lqnt.lockbox.cipher.CipherInterface; | ||
import co.lqnt.lockbox.cipher.EncryptCipher; | ||
import co.lqnt.lockbox.cipher.parameters.CipherParametersInterface; | ||
import co.lqnt.lockbox.key.Key; | ||
import com.google.common.primitives.Bytes; | ||
import java.nio.charset.Charset; | ||
import java.util.List; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class UnsupportedCipherParametersExceptionTest | ||
{ | ||
public UnsupportedCipherParametersExceptionTest() throws Throwable | ||
{ | ||
this.cipher = new EncryptCipher(); | ||
this.bytes16 = Bytes.asList("1234567890123456".getBytes(Charset.forName("US-ASCII"))); | ||
this.bytes28 = Bytes.asList("1234567890123456789012345678".getBytes(Charset.forName("US-ASCII"))); | ||
this.parameters = new Key(this.bytes16, this.bytes28); | ||
} | ||
|
||
@Test | ||
public void testException() | ||
{ | ||
Exception cause = new Exception(); | ||
UnsupportedCipherParametersException exception = new UnsupportedCipherParametersException(this.cipher, this.parameters, cause); | ||
|
||
Assert.assertSame(this.cipher, exception.cipher()); | ||
Assert.assertEquals( | ||
exception.getMessage(), | ||
"Cipher of type " + | ||
"co.lqnt.lockbox.cipher.EncryptCipher" + | ||
" does not support parameters of type " + | ||
"co.lqnt.lockbox.key.Key" + | ||
"." | ||
); | ||
Assert.assertSame(exception.getCause(), cause); | ||
} | ||
|
||
@Test | ||
public void testExceptionWithoutCause() | ||
{ | ||
UnsupportedCipherParametersException exception = new UnsupportedCipherParametersException(this.cipher, this.parameters); | ||
|
||
Assert.assertSame(this.cipher, exception.cipher()); | ||
Assert.assertEquals( | ||
exception.getMessage(), | ||
"Cipher of type " + | ||
"co.lqnt.lockbox.cipher.EncryptCipher" + | ||
" does not support parameters of type " + | ||
"co.lqnt.lockbox.key.Key" + | ||
"." | ||
); | ||
Assert.assertNull(exception.getCause()); | ||
} | ||
|
||
final private CipherInterface cipher; | ||
final private CipherParametersInterface parameters; | ||
final private List<Byte> bytes16; | ||
final private List<Byte> bytes28; | ||
} |