Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed May 27, 2014
1 parent 966036f commit a7c20ee
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public CipherNotInitializedException(
final CipherInterface cipher,
final Throwable cause
) {
super(cipher, "The cipher is not initialized finalized.", cause);
super(cipher, "The cipher is not initialized.", cause);
}
}
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;
}
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;
}
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;
}

0 comments on commit a7c20ee

Please sign in to comment.