Update test coverage

This commit is contained in:
2023-04-14 19:01:58 -04:00
parent bd086a2ab3
commit 575ff04ecd
8 changed files with 405 additions and 446 deletions

View File

@@ -16,23 +16,23 @@ import com.mattrixwv.cipherstream.polysubstitution.PolybiusSquare;
public class ADFGX{
private static final Logger logger = LoggerFactory.getLogger(ADFGX.class);
protected static Logger logger = LoggerFactory.getLogger(ADFGX.class);
//Internal fields
private String inputString; //The string that needs encoded/decoded
private String outputString; //The string that is output after encoding/decoding
private String squareKeyword; //The keyword used in the Polybius Square
private String keyword; //The keyword used in the Columnar cipher
private boolean preserveCapitals; //Whether to respect capitals in the output string
private boolean preserveWhitespace; //Whether to respect whitespace in the output string
private boolean preserveSymbols; //Whether to respect symbols in the output string
protected String inputString; //The string that needs encoded/decoded
protected String outputString; //The string that is output after encoding/decoding
protected String squareKeyword; //The keyword used in the Polybius Square
protected String keyword; //The keyword used in the Columnar cipher
protected boolean preserveCapitals; //Whether to respect capitals in the output string
protected boolean preserveWhitespace; //Whether to respect whitespace in the output string
protected boolean preserveSymbols; //Whether to respect symbols in the output string
//Internal ciphers
private PolybiusSquare polybiusSquare; //The first step in encoding
private Columnar columnar; //The second step in encoding
protected PolybiusSquare polybiusSquare; //The first step in encoding
protected Columnar columnar; //The second step in encoding
//Ensures Polybius keyword constraints
private void setSquareKeyword(String squareKeyword) throws InvalidKeywordException{
protected void setSquareKeyword(String squareKeyword) throws InvalidKeywordException{
if(squareKeyword == null){
throw new InvalidKeywordException("Square keyword cannot be null");
}
@@ -41,7 +41,7 @@ public class ADFGX{
this.squareKeyword = squareKeyword;
}
//Ensures Columnar keyword constraints
private void setKeyword(String keyword) throws InvalidKeywordException{
protected void setKeyword(String keyword) throws InvalidKeywordException{
if(keyword == null){
throw new InvalidKeywordException("Keyword cannot be null");
}
@@ -50,7 +50,7 @@ public class ADFGX{
this.keyword = keyword;
}
//Ensures inputString constraints
private void setInputString(String inputString) throws InvalidInputException{
protected void setInputString(String inputString) throws InvalidInputException{
if(inputString == null){
throw new InvalidInputException("Input cannot be null");
}
@@ -80,7 +80,7 @@ public class ADFGX{
logger.debug("cleaned input string '{}'", inputString);
}
//Format the output string with capitals, symbols, and numbers that are in the input string
private void formatOutputStringEncode(){
protected void formatOutputStringEncode(){
logger.debug("Formatting output string to match input string");
StringBuilder output = new StringBuilder();
@@ -109,7 +109,7 @@ public class ADFGX{
logger.debug("Saving output string '{}'", outputString);
outputString = output.toString();
}
private void formatOutputStringDecode(){
protected void formatOutputStringDecode(){
logger.debug("Formatting output string to match input string");
StringBuilder output = new StringBuilder();
int outputLocation = 0;
@@ -139,7 +139,7 @@ public class ADFGX{
outputString = output.toString();
}
//Encodes the inputString and stores the result in outputString
private void encode() throws InvalidCharacterException, InvalidInputException, InvalidKeywordException{
protected void encode() throws InvalidCharacterException, InvalidInputException, InvalidKeywordException{
//Encode the input with polybius
logger.debug("Encoding using Polybius Square");
String polybiusOutput = polybiusSquare.encode(squareKeyword, inputString);
@@ -158,7 +158,7 @@ public class ADFGX{
formatOutputStringEncode();
}
//Decodes the inputString and stores the result in outputString
private void decode() throws InvalidKeywordException, InvalidCharacterException, InvalidInputException{
protected void decode() throws InvalidKeywordException, InvalidCharacterException, InvalidInputException{
//Decode the input with columnar
logger.debug("Decoding using columnar");
String columnarOutput = columnar.decode(keyword, inputString);

View File

@@ -1,450 +1,199 @@
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamjava/combination/TestADFGX.java
//Mattrixwv
// Created: 01-25-22
//Modified: 07-09-22
//Modified: 04-14-23
package com.mattrixwv.cipherstream.combination;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
@ExtendWith(MockitoExtension.class)
public class TestADFGX{
@Test
public void testEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(true, true, true);
private ADFGX cipher;
private Logger logger;
//Test lowercase encoding
String inputString = "messagetoencode";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
String output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "aagagadfagaxxd axdx adafafxddgdf";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "aagagadfagaxxd*axdx+adafafxddgdf-";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test mixed case, whitespace, and symbol encoding
inputString = "Message to^encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAgagadfagaxxd axdx^adafafxddgdf";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
}
@Test
public void testNoCapitalEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(false, true, true);
//Test lowercase encoding
String inputString = "messagetoencode";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
String output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXD AXDX ADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXD*AXDX+ADAFAFXDDGDF-";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test mixed case, whitespace, and symbol encoding
inputString = "Message to^encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXD AXDX^ADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
}
@Test
public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(true, false, true);
//Test lowercase encoding
String inputString = "messagetoencode";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
String output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "aagagadfagaxxd*axdx+adafafxddgdf-";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test mixed case, whitespace, and symbol encoding
inputString = "Message to^encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAgagadfagaxxdaxdx^adafafxddgdf";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
}
@Test
public void testNoSymbolEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(true, true, false);
//Test lowercase encoding
String inputString = "messagetoencode";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
String output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "aagagadfagaxxd axdx adafafxddgdf";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test mixed case, whitespace, and symbol encoding
inputString = "Message to^encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAgagadfagaxxd axdxadafafxddgdf";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
}
@Test
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(false, false, false);
//Test lowercase encoding
String inputString = "messagetoencode";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
String output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test uppercase encoding
inputString = "MESSAGETOENCODE";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test whitespace encoding
inputString = "message to encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test symbol encoding
inputString = "message*to+encode-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test mixed case, whitespace, and symbol encoding
inputString = "Message to^encode";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
output = cipher.encode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
@BeforeEach
public void setup(){
cipher = new ADFGX();
logger = mock(Logger.class);
ADFGX.logger = logger;
}
@Test
public void testDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(true, true, true);
public void testSetSquareKeyword(){
assertThrows(InvalidKeywordException.class, () -> {
cipher.setSquareKeyword(null);
});
assertEquals("", cipher.squareKeyword);
verify(logger, never()).debug(anyString(), anyString());
//Test lowercase decoding
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "messagetoencode";
String output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test uppercase decoding
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test whitespace decoding
inputString = "aagagadfagaxxd axdx adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "message to encode";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test symbol decoding
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "message*to+encode-";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "Message to^encode";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
String squareKeyword = "squareKeyword";
cipher.setSquareKeyword(squareKeyword);
assertEquals(squareKeyword, cipher.squareKeyword);
verify(logger, times(1)).debug("squareKeyword = {}", squareKeyword);
}
@Test
public void testNoCapitalDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(false, true, true);
public void testSetKeyword(){
assertThrows(InvalidKeywordException.class, () -> {
cipher.setKeyword(null);
});
assertEquals("", cipher.keyword);
verify(logger, never()).debug(anyString(), anyString());
//Test lowercase decoding
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "MESSAGETOENCODE";
String output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test uppercase decoding
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test whitespace decoding
inputString = "aagagadfagaxxd axdx adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGE TO ENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test symbol decoding
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGE*TO+ENCODE-";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGE TO^ENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
cipher.setKeyword(keyword);
assertEquals(keyword, cipher.keyword);
verify(logger, times(1)).debug("keyword = {}", keyword);
}
@Test
public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(true, false, true);
public void testSetInputString(){
//Null input
assertThrows(InvalidInputException.class, () -> {
cipher.setInputString(null);
});
assertEquals("", cipher.inputString);
verify(logger, never()).debug(anyString(), anyString());
//Test lowercase decoding
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "messagetoencode";
String output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test uppercase decoding
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
String originalInputString = "original input string '{}'";
String cleanedInputString = "cleaned input string '{}'";
//Test whitespace decoding
inputString = "aagagadfagaxxd axdx adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "messagetoencode";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Blank input
cipher.preserveCapitals = true;
cipher.preserveSymbols = true;
cipher.preserveWhitespace = true;
assertThrows(InvalidInputException.class, () -> {
cipher.setInputString("");
});
assertEquals("", cipher.inputString);
verify(logger, times(1)).debug(originalInputString, "");
//Test symbol decoding
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "message*to+encode-";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//No options
String inputString = "input String*";
cipher.setInputString(inputString);
assertEquals(inputString, cipher.inputString);
verify(logger, times(1)).debug(originalInputString, inputString);
verify(logger, times(1)).debug(cleanedInputString, inputString);
//Test mixed case, whitespace, and symbol decoding
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "Messageto^encode";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//capitals
cipher.preserveCapitals = false;
cipher.preserveWhitespace = true;
cipher.preserveSymbols = true;
inputString = "input String*";
cipher.setInputString(inputString);
assertEquals(inputString.toUpperCase(), cipher.inputString);
verify(logger, times(2)).debug(originalInputString, inputString);
verify(logger, times(1)).debug("Removing capitals");
verify(logger, times(1)).debug(cleanedInputString, inputString.toUpperCase());
//whitespace
cipher.preserveCapitals = true;
cipher.preserveWhitespace = false;
cipher.preserveSymbols = true;
inputString = "input String*";
cipher.setInputString(inputString);
assertEquals(inputString.replaceAll("\\s", ""), cipher.inputString);
verify(logger, times(3)).debug(originalInputString, inputString);
verify(logger, times(1)).debug("Removing whitespace");
verify(logger, times(1)).debug(cleanedInputString, inputString.replaceAll("\\s", ""));
//symbols
cipher.preserveCapitals = true;
cipher.preserveWhitespace = true;
cipher.preserveSymbols = false;
inputString = "input String*";
cipher.setInputString(inputString);
assertEquals(inputString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
verify(logger, times(4)).debug(originalInputString, inputString);
verify(logger, times(1)).debug("Removing symbols");
verify(logger, times(1)).debug(cleanedInputString, inputString.replaceAll("[^a-zA-Z\\s]", ""));
}
@Test
public void testNoSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(true, true, false);
//Test lowercase decoding
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "messagetoencode";
String output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test uppercase decoding
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test whitespace decoding
inputString = "aagagadfagaxxd axdx adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "message to encode";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test symbol decoding
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "messagetoencode";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test mixed case, whitespace, and symbol decoding
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "Message toencode";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
public void testFormatOutputStringEncode(){
//TODO:
}
@Test
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
ADFGX cipher = new ADFGX(false, false, false);
public void formatOutputStringDecode(){
//TODO:
}
//Test lowercase decoding
String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
String squareKeyword = "SquareKeyword";
String keyword = "keyword";
String correctOutput = "MESSAGETOENCODE";
String output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test uppercase decoding
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
@Test
public void testEncodePrivate(){
//TODO:
}
//Test whitespace decoding
inputString = "aagagadfagaxxd axdx adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
@Test
public void testDecodePrivate(){
//TODO:
}
//Test symbol decoding
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
@Test
public void testConstructors(){
//TODO:
}
//Test mixed case, whitespace, and symbol decoding
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
squareKeyword = "SquareKeyword";
keyword = "keyword";
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
@Test
public void testGetters(){
//TODO:
}
@Test
public void testReset(){
//TODO:
}
@Test
public void testPracticalEncoding(){
//Test as original
cipher.preserveCapitals = true;
cipher.preserveWhitespace = true;
cipher.preserveSymbols = true;
String output = cipher.encode("SquareKeyword", "keyword", "Message to^encode");
assertEquals("AAgagadfagaxxd axdx^adafafxddgdf", output);
//Test fully cleaned
cipher.preserveCapitals = false;
cipher.preserveWhitespace = false;
cipher.preserveSymbols = false;
output = cipher.encode("SquareKeyword", "keyword", "Message to^encode");
assertEquals("AAGAGADFAGAXXDAXDXADAFAFXDDGDF", output);
}
@Test
public void testPracticalDecoding(){
//Test as original
cipher.preserveCapitals = true;
cipher.preserveWhitespace = true;
cipher.preserveSymbols = true;
String output = cipher.decode("SquareKeyword", "keyword", "AAgagadfagaxxd axdx^adafafxddgdf");
assertEquals("Message to^encode", output);
//Test fully cleaned
cipher.preserveCapitals = false;
cipher.preserveWhitespace = false;
cipher.preserveSymbols = false;
output = cipher.decode("SquareKeyword", "keyword", "AAgagadfagaxxd axdx^adafafxddgdf");
assertEquals("MESSAGETOENCODE", output);
}
}

View File

@@ -0,0 +1,37 @@
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidBaseException.java
//Mattrixwv
// Created: 04-14-23
//Modified: 04-14-23
package com.mattrixwv.cipherstream.exceptions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
public class TestInvalidBaseException{
private String message = "message";
private Throwable cause = new Exception();
@Test
public void testConstructors(){
InvalidBaseException exception = new InvalidBaseException();
assertNull(exception.getMessage());
assertNull(exception.getCause());
exception = new InvalidBaseException(message);
assertEquals(message, exception.getMessage());
assertNull(exception.getCause());
exception = new InvalidBaseException(cause);
assertEquals(cause.toString(), exception.getMessage());
assertEquals(cause, exception.getCause());
exception = new InvalidBaseException(message, cause);
assertEquals(message, exception.getMessage());
assertEquals(cause, exception.getCause());
}
}

View File

@@ -0,0 +1,37 @@
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidcharacterException.java
//Mattrixwv
// Created: 04-14-23
//Modified: 04-14-23
package com.mattrixwv.cipherstream.exceptions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
public class TestInvalidCharacterException{
private String message = "message";
private Throwable cause = new Exception();
@Test
public void testConstructors(){
InvalidCharacterException exception = new InvalidCharacterException();
assertNull(exception.getMessage());
assertNull(exception.getCause());
exception = new InvalidCharacterException(message);
assertEquals(message, exception.getMessage());
assertNull(exception.getCause());
exception = new InvalidCharacterException(cause);
assertEquals(cause.toString(), exception.getMessage());
assertEquals(cause, exception.getCause());
exception = new InvalidCharacterException(message, cause);
assertEquals(message, exception.getMessage());
assertEquals(cause, exception.getCause());
}
}

View File

@@ -0,0 +1,37 @@
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exception/TestInvalidInputException.java
//Mattrixwv
// Created: 04-14-23
//Modified: 04-14-23
package com.mattrixwv.cipherstream.exceptions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
public class TestInvalidInputException{
private String message = "message";
private Throwable cause = new Exception();
@Test
public void testConstructors(){
InvalidInputException exception = new InvalidInputException();
assertNull(exception.getMessage());
assertNull(exception.getCause());
exception = new InvalidInputException(message);
assertEquals(message, exception.getMessage());
assertNull(exception.getCause());
exception = new InvalidInputException(cause);
assertEquals(cause.toString(), exception.getMessage());
assertEquals(cause, exception.getCause());
exception = new InvalidInputException(message, cause);
assertEquals(message, exception.getMessage());
assertEquals(cause, exception.getCause());
}
}

View File

@@ -0,0 +1,37 @@
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidKeyException.java
//Mattrixwv
// Created: 04-14-23
//Modified: 04-14-23
package com.mattrixwv.cipherstream.exceptions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
public class TestInvalidKeyException{
public String message = "message";
public Throwable cause = new Exception();
@Test
public void testConstructors(){
InvalidKeyException exception = new InvalidKeyException();
assertNull(exception.getMessage());
assertNull(exception.getCause());
exception = new InvalidKeyException(message);
assertEquals(message, exception.getMessage());
assertNull(exception.getCause());
exception = new InvalidKeyException(cause);
assertEquals(cause.toString(), exception.getMessage());
assertEquals(cause, exception.getCause());
exception = new InvalidKeyException(message, cause);
assertEquals(message, exception.getMessage());
assertEquals(cause, exception.getCause());
}
}

View File

@@ -0,0 +1,37 @@
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidKeywordException.java
//Mattrixwv
// Created: 04-14-23
//Modified: 04-14-23
package com.mattrixwv.cipherstream.exceptions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
public class TestInvalidKeywordException{
private String message = "message";
private Throwable cause = new Exception();
@Test
public void testConstructor(){
InvalidKeywordException exception = new InvalidKeywordException();
assertNull(exception.getMessage());
assertNull(exception.getCause());
exception = new InvalidKeywordException(message);
assertEquals(message, exception.getMessage());
assertNull(exception.getCause());
exception = new InvalidKeywordException(cause);
assertEquals(cause.toString(), exception.getMessage());
assertEquals(cause, exception.getCause());
exception = new InvalidKeywordException(message, cause);
assertEquals(message, exception.getMessage());
assertEquals(cause, exception.getCause());
}
}