Updating tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/combination/TestADFGVX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-26-22
|
||||
//Modified: 04-21-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.combination;
|
||||
|
||||
|
||||
@@ -14,13 +14,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
@@ -29,8 +31,11 @@ import com.mattrixwv.cipherstream.polysubstitution.Columnar;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.LargePolybiusSquare;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestADFGVX{
|
||||
@InjectMocks
|
||||
private ADFGVX cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "Message to^encode";
|
||||
@@ -41,102 +46,200 @@ public class TestADFGVX{
|
||||
private String squareKeyword = "SquareKeyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new ADFGVX();
|
||||
logger = mock(Logger.class);
|
||||
ADFGVX.logger = logger;
|
||||
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.largePolybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_preservesCapitals(){
|
||||
cipher = new ADFGVX(true, false, false);
|
||||
|
||||
assertTrue(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.largePolybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSquareKeyword(){
|
||||
public void testConstructor_preservesWhitespace(){
|
||||
cipher = new ADFGVX(false, true, false);
|
||||
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertTrue(cipher.preserveWhitespace);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.largePolybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_preservesSymbols(){
|
||||
cipher = new ADFGVX(false, false, true);
|
||||
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertTrue(cipher.preserveSymbols);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.largePolybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSquareKeyword(){
|
||||
cipher.setSquareKeyword(squareKeyword);
|
||||
|
||||
assertEquals(squareKeyword, cipher.squareKeyword);
|
||||
verify(logger, times(1)).debug("squareKeyword '{}'", squareKeyword);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSquareKeyword_null(){
|
||||
assertThrows(InvalidKeywordException.class, () -> {
|
||||
cipher.setSquareKeyword(null);
|
||||
});
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
|
||||
cipher.setSquareKeyword(squareKeyword);
|
||||
assertEquals(squareKeyword, cipher.squareKeyword);
|
||||
verify(logger, times(1)).debug("squareKeyword = {}", squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
verify(logger, never()).debug(eq("squareKeyword '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
|
||||
assertEquals(keyword, cipher.keyword);
|
||||
verify(logger, times(1)).debug("keyword '{}'", keyword);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword_null(){
|
||||
assertThrows(InvalidKeywordException.class, () -> {
|
||||
cipher.setKeyword(null);
|
||||
});
|
||||
assertEquals("", cipher.keyword);
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
|
||||
String keyword = "keyword";
|
||||
cipher.setKeyword(keyword);
|
||||
assertEquals(keyword, cipher.keyword);
|
||||
verify(logger, times(1)).debug("keyword = {}", keyword);
|
||||
assertEquals("", cipher.keyword);
|
||||
verify(logger, never()).debug(eq("keyword '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString(){
|
||||
//Null input
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString(null);
|
||||
});
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
|
||||
String originalInputString = "Original input string '{}'";
|
||||
String cleanedInputString = "Cleaned input string '{}'";
|
||||
|
||||
//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, "");
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
//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);
|
||||
cipher.setInputString(decodedString);
|
||||
|
||||
//capitals
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString_noCapitals(){
|
||||
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.setInputString(decodedString);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString_noWhitespace(){
|
||||
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.setInputString(decodedString);
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString_noSymbols(){
|
||||
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);
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug(cleanedInputString, inputString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString_blank(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString("");
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", "");
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString_null(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString(null);
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, never()).debug(eq("Original input string '{}'"), anyString());
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, never()).debug(eq("Cleaned input string '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,6 +248,7 @@ public class TestADFGVX{
|
||||
cipher.outputString = encodedStringClean;
|
||||
|
||||
cipher.formatOutputStringEncode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string to match input string");
|
||||
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
||||
@@ -160,6 +264,7 @@ public class TestADFGVX{
|
||||
cipher.inputString = encodedString;
|
||||
|
||||
cipher.formatOutputStringDecode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string to match input string");
|
||||
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
||||
@@ -197,62 +302,6 @@ public class TestADFGVX{
|
||||
verify(logger, times(1)).debug("Decoding using Polybius Square");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new ADFGVX();
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.largePolybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_preservesCapitals(){
|
||||
cipher = new ADFGVX(true, false, false);
|
||||
assertTrue(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.largePolybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_preservesWhitespace(){
|
||||
cipher = new ADFGVX(false, true, false);
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertTrue(cipher.preserveWhitespace);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.largePolybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_preservesSymbols(){
|
||||
cipher = new ADFGVX(false, false, true);
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertTrue(cipher.preserveSymbols);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.largePolybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamjava/combination/TestADFGX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-25-22
|
||||
//Modified: 04-17-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.combination;
|
||||
|
||||
|
||||
@@ -14,13 +14,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
@@ -29,8 +31,11 @@ import com.mattrixwv.cipherstream.polysubstitution.Columnar;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.PolybiusSquare;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestADFGX{
|
||||
@InjectMocks
|
||||
private ADFGX cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "Message to^encode";
|
||||
@@ -41,102 +46,199 @@ public class TestADFGX{
|
||||
private String squareKeyword = "SquareKeyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new ADFGX(true, true, true);
|
||||
logger = mock(Logger.class);
|
||||
ADFGX.logger = logger;
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new ADFGX();
|
||||
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.polybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_preservesCapitals(){
|
||||
cipher = new ADFGX(true, false, false);
|
||||
|
||||
assertTrue(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.polybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_preservesWhitespace(){
|
||||
cipher = new ADFGX(false, true, false);
|
||||
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertTrue(cipher.preserveWhitespace);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.polybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_preservesSymbols(){
|
||||
cipher = new ADFGX(false, false, true);
|
||||
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertTrue(cipher.preserveSymbols);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.polybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSquareKeyword(){
|
||||
cipher.setSquareKeyword(squareKeyword);
|
||||
assertEquals(squareKeyword, cipher.squareKeyword);
|
||||
verify(logger, times(1)).debug("Square keyword '{}'", squareKeyword);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSquareKeyword_null(){
|
||||
assertThrows(InvalidKeywordException.class, () -> {
|
||||
cipher.setSquareKeyword(null);
|
||||
});
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
|
||||
cipher.setSquareKeyword(squareKeyword);
|
||||
assertEquals(squareKeyword, cipher.squareKeyword);
|
||||
verify(logger, times(1)).debug("squareKeyword = {}", squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
verify(logger, never()).debug(eq("Square keyword '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
|
||||
assertEquals(keyword, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Keyword '{}'", keyword);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword_null(){
|
||||
assertThrows(InvalidKeywordException.class, () -> {
|
||||
cipher.setKeyword(null);
|
||||
});
|
||||
assertEquals("", cipher.keyword);
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
|
||||
String keyword = "keyword";
|
||||
cipher.setKeyword(keyword);
|
||||
assertEquals(keyword, cipher.keyword);
|
||||
verify(logger, times(1)).debug("keyword = {}", keyword);
|
||||
assertEquals("", cipher.keyword);
|
||||
verify(logger, never()).debug(eq("Keyword '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString(){
|
||||
//Null input
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString(null);
|
||||
});
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
|
||||
String originalInputString = "Original input string '{}'";
|
||||
String cleanedInputString = "Cleaned input string '{}'";
|
||||
|
||||
//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, "");
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
//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);
|
||||
cipher.setInputString(decodedString);
|
||||
|
||||
//capitals
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString_noCapitals(){
|
||||
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.setInputString(decodedString);
|
||||
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString_noWhitespace(){
|
||||
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.setInputString(decodedString);
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString_noSymbols(){
|
||||
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);
|
||||
|
||||
cipher.setInputString(decodedString);
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug(cleanedInputString, inputString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString_blank(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString("");
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", "");
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString_null(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString(null);
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, never()).debug(eq("Original input string '{}'"), anyString());
|
||||
verify(logger, never()).debug("Removing capitals");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, never()).debug(eq("Cleaned input string '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,6 +247,7 @@ public class TestADFGX{
|
||||
cipher.outputString = encodedStringClean;
|
||||
|
||||
cipher.formatOutputStringEncode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string to match input string");
|
||||
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
||||
@@ -160,6 +263,7 @@ public class TestADFGX{
|
||||
cipher.inputString = encodedString;
|
||||
|
||||
cipher.formatOutputStringDecode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string to match input string");
|
||||
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
|
||||
@@ -197,62 +301,6 @@ public class TestADFGX{
|
||||
verify(logger, times(1)).debug("Decoding using Polybius Square");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new ADFGX();
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.polybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_preservesCapitals(){
|
||||
cipher = new ADFGX(true, false, false);
|
||||
assertTrue(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.polybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_preservesWhitespace(){
|
||||
cipher = new ADFGX(false, true, false);
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertTrue(cipher.preserveWhitespace);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.polybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_preservesSymbols(){
|
||||
cipher = new ADFGX(false, false, true);
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertTrue(cipher.preserveSymbols);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertEquals("", cipher.squareKeyword);
|
||||
assertNotNull(cipher.polybiusSquare);
|
||||
assertNotNull(cipher.columnar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestAffine.java
|
||||
//Mattrixwv
|
||||
// Created: 01-26-22
|
||||
//Modified: 04-17-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -10,24 +10,28 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestAffine{
|
||||
@InjectMocks
|
||||
private Affine cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "MEssage to^encode";
|
||||
@@ -38,17 +42,10 @@ public class TestAffine{
|
||||
private int key2 = 7;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new Affine();
|
||||
logger = mock(Logger.class);
|
||||
Affine.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new Affine();
|
||||
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
@@ -61,6 +58,7 @@ public class TestAffine{
|
||||
@Test
|
||||
public void testConstructor_preservesCapitals(){
|
||||
cipher = new Affine(true, false, false);
|
||||
|
||||
assertTrue(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
@@ -73,6 +71,7 @@ public class TestAffine{
|
||||
@Test
|
||||
public void testConstructor_preservesWhitespace(){
|
||||
cipher = new Affine(false, true, false);
|
||||
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertTrue(cipher.preserveWhitespace);
|
||||
@@ -85,6 +84,7 @@ public class TestAffine{
|
||||
@Test
|
||||
public void testConstructor_preservesSymbols(){
|
||||
cipher = new Affine(false, false, true);
|
||||
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertTrue(cipher.preserveSymbols);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
@@ -97,12 +97,10 @@ public class TestAffine{
|
||||
@Test
|
||||
public void testKey1(){
|
||||
cipher.setKey1(key1);
|
||||
|
||||
assertEquals(key1, cipher.key1);
|
||||
verify(logger, times(1)).debug("Setting key1 {}", key1);
|
||||
verify(logger, times(1)).debug("Cleaned key1 {}", key1);
|
||||
verify(logger, times(2)).debug(anyString(), anyInt());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,66 +108,54 @@ public class TestAffine{
|
||||
assertThrows(InvalidKeywordException.class, () -> {
|
||||
cipher.setKey1(2);
|
||||
});
|
||||
|
||||
verify(logger, times(1)).debug("Setting key1 {}", 2);
|
||||
verify(logger, never()).debug("Cleaned key1 {}", 2);
|
||||
verify(logger, times(1)).debug(anyString(), anyInt());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey1_negative(){
|
||||
cipher.setKey1(-27);
|
||||
|
||||
assertEquals(25, cipher.key1);
|
||||
verify(logger, times(1)).debug("Setting key1 {}", -27);
|
||||
verify(logger, times(1)).debug("Cleaned key1 {}", 25);
|
||||
verify(logger, times(2)).debug(anyString(), anyInt());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey1_large(){
|
||||
cipher.setKey1(key1 + 26);
|
||||
|
||||
assertEquals(key1, cipher.key1);
|
||||
verify(logger, times(1)).debug("Setting key1 {}", key1 + 26);
|
||||
verify(logger, times(1)).debug("Cleaned key1 {}", key1);
|
||||
verify(logger, times(2)).debug(anyString(), anyInt());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey2(){
|
||||
cipher.setKey2(key2);
|
||||
|
||||
assertEquals(key2, cipher.key2);
|
||||
verify(logger, times(1)).debug("Setting key2 {}", key2);
|
||||
verify(logger, times(1)).debug("Cleaned key2 {}", key2);
|
||||
verify(logger, times(2)).debug(anyString(), anyInt());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey2_negative(){
|
||||
cipher.setKey2(-27);
|
||||
|
||||
assertEquals(25, cipher.key2);
|
||||
verify(logger, times(1)).debug("Setting key2 {}", -27);
|
||||
verify(logger, times(1)).debug("Cleaned key2 {}", cipher.key2);
|
||||
verify(logger, times(2)).debug(anyString(), anyInt());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey2_large(){
|
||||
cipher.setKey2(key2 + 26);
|
||||
|
||||
assertEquals(key2, cipher.key2);
|
||||
verify(logger, times(1)).debug("Setting key2 {}", key2 + 26);
|
||||
verify(logger, times(1)).debug("Cleaned key2 {}", key2);
|
||||
verify(logger, times(2)).debug(anyString(), anyInt());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -182,8 +168,10 @@ public class TestAffine{
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -197,9 +185,9 @@ public class TestAffine{
|
||||
assertEquals(decodedString.toLowerCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toLowerCase());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
verify(logger, times(1)).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -212,10 +200,10 @@ public class TestAffine{
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing sybols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
verify(logger, times(1)).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -228,10 +216,10 @@ public class TestAffine{
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
verify(logger, times(1)).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -243,8 +231,13 @@ public class TestAffine{
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString(null);
|
||||
});
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, never()).debug(eq("Original input string '{}'"), anyString());
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, never()).debug(eq("Cleaned input string '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -256,10 +249,13 @@ public class TestAffine{
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString("");
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", "");
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", "");
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestAtbash.java
|
||||
//Mattrixwv
|
||||
// Created: 07-25-21
|
||||
//Modified: 04-17-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -9,21 +9,28 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestAtbash{
|
||||
@InjectMocks
|
||||
private Atbash cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "Message to^encode";
|
||||
@@ -32,17 +39,10 @@ public class TestAtbash{
|
||||
private String encodedStringClean = "NVHHZTVGLVMXLWV";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new Atbash();
|
||||
logger = mock(Logger.class);
|
||||
Atbash.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new Atbash();
|
||||
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
@@ -53,6 +53,7 @@ public class TestAtbash{
|
||||
@Test
|
||||
public void testConstructor_preservesCapitals(){
|
||||
cipher = new Atbash(true, false, false);
|
||||
|
||||
assertTrue(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
@@ -63,6 +64,7 @@ public class TestAtbash{
|
||||
@Test
|
||||
public void testConstructor_preservesWhitespace(){
|
||||
cipher = new Atbash(false, true, false);
|
||||
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertTrue(cipher.preserveWhitespace);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
@@ -73,6 +75,7 @@ public class TestAtbash{
|
||||
@Test
|
||||
public void testConstructor_preservesSymbols(){
|
||||
cipher = new Atbash(false, false, true);
|
||||
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertTrue(cipher.preserveSymbols);
|
||||
@@ -83,10 +86,16 @@ public class TestAtbash{
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(17)).debug(eq("Encoding char {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Encoding uppercase");
|
||||
verify(logger, times(14)).debug("Encoding lowercase");
|
||||
verify(logger, times(2)).debug("Appending symbol");
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", encodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,9 +108,10 @@ public class TestAtbash{
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,9 +125,9 @@ public class TestAtbash{
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
verify(logger, times(1)).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,10 +140,10 @@ public class TestAtbash{
|
||||
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
verify(logger, times(1)).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -146,10 +156,10 @@ public class TestAtbash{
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
verify(logger, times(1)).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -163,8 +173,11 @@ public class TestAtbash{
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, never()).debug(eq("Original input string '{}'"), anyString());
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, never()).debug(eq("Cleaned input string '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,9 +193,10 @@ public class TestAtbash{
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", "");
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", "");
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestAutokey.java
|
||||
//Mattrixwv
|
||||
// Created: 07-26-21
|
||||
//Modified: 04-17-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -9,24 +9,26 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestAutokey{
|
||||
@InjectMocks
|
||||
private Autokey cipher;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.monosubstitution.Autokey")
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "MeSsage to^encode";
|
||||
@@ -37,17 +39,10 @@ public class TestAutokey{
|
||||
private ArrayList<Integer> offset = new ArrayList<>(List.of(10, 4, 24, 22, 14, 17, 3, 12, 4, 18, 18, 0, 6, 4, 19));
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new Autokey();
|
||||
logger = mock(Logger.class);
|
||||
Autokey.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new Autokey();
|
||||
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
@@ -60,6 +55,7 @@ public class TestAutokey{
|
||||
@Test
|
||||
public void testConstructor_preservesCapitals(){
|
||||
cipher = new Autokey(true, false, false);
|
||||
|
||||
assertTrue(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
@@ -110,7 +106,6 @@ public class TestAutokey{
|
||||
verify(logger, times(1)).debug("Setting keyword");
|
||||
verify(logger, times(1)).debug("Adding input to keyword");
|
||||
verify(logger, times(1)).debug("Removing last letters in the keyword");
|
||||
verify(logger, times(4)).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,7 +121,6 @@ public class TestAutokey{
|
||||
verify(logger, times(1)).debug("Setting fields for decoding");
|
||||
verify(logger, times(1)).debug("Setting keyword");
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(3)).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,9 +128,7 @@ public class TestAutokey{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
Autokey.logger = mock(Logger.class);
|
||||
cipher.decodeSet(keyword, encodedString);
|
||||
Autokey.logger = logger;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
@@ -227,40 +219,4 @@ public class TestAutokey{
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetKeyword() throws InvalidKeywordException{
|
||||
Autokey cipher = new Autokey();
|
||||
|
||||
//Test keyword with whitespace
|
||||
String keyword = "x y z ";
|
||||
String correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
String output = cipher.getKeyword();
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test keyword with symbol
|
||||
keyword = "x-y@z0";
|
||||
correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
output = cipher.getKeyword();
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test keyword with mixed case
|
||||
keyword = "xYz";
|
||||
correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
output = cipher.getKeyword();
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test keyword with whitespace, symbol and keyword
|
||||
keyword = "x Y%z ";
|
||||
correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
output = cipher.getKeyword();
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/TestBaconian.java
|
||||
//Mattrixwv
|
||||
// Created: 01-12-22
|
||||
//Modified: 04-17-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -13,21 +13,26 @@ import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestBaconian{
|
||||
@InjectMocks
|
||||
private Baconian cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "Message to-encode";
|
||||
@@ -36,14 +41,6 @@ public class TestBaconian{
|
||||
private String encodedString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new Baconian();
|
||||
logger = mock(Logger.class);
|
||||
Baconian.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new Baconian();
|
||||
@@ -72,8 +69,6 @@ public class TestBaconian{
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringClean);
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,8 +81,6 @@ public class TestBaconian{
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringCleanLower);
|
||||
verify(logger, times(1)).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,8 +95,6 @@ public class TestBaconian{
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", "");
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", "");
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,8 +106,9 @@ public class TestBaconian{
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug("Setting input string for encoding '{}'", "");
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Cleaned input string '{}'", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -132,8 +124,6 @@ public class TestBaconian{
|
||||
verify(logger, times(15)).debug(eq("Current 'letter' {}"), anyString());
|
||||
verify(logger, times(15)).debug("Replacing all non-abAB characters");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString);
|
||||
verify(logger, times(16)).debug(anyString());
|
||||
verify(logger, times(17)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,8 +139,6 @@ public class TestBaconian{
|
||||
verify(logger, times(15)).debug(eq("Current 'letter' {}"), anyString());
|
||||
verify(logger, times(15)).debug("Replacing all non-abAB characters");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString.toLowerCase());
|
||||
verify(logger, times(17)).debug(anyString());
|
||||
verify(logger, times(17)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -168,8 +156,6 @@ public class TestBaconian{
|
||||
verify(logger, times(1)).debug(eq("Current 'letter' {}"), anyString());
|
||||
verify(logger, never()).debug("Replacing all non-abAB characters");
|
||||
verify(logger, never()).debug(eq("Cleaned input string '{}'"), anyString());
|
||||
verify(logger, times(1)).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,8 +173,6 @@ public class TestBaconian{
|
||||
verify(logger, times(1)).debug("Current 'letter' {}", "ccccc");
|
||||
verify(logger, times(1)).debug("Replacing all non-abAB characters");
|
||||
verify(logger, never()).debug(eq("Cleaned input string '{}'"), anyString());
|
||||
verify(logger, times(2)).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -200,14 +184,12 @@ public class TestBaconian{
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, never()).debug("Setting input string for decoding '{}'", "");
|
||||
verify(logger, never()).debug(eq("Setting input string for decoding '{}'"), anyString());
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Ensuring all 'letters' contain 5 characters");
|
||||
verify(logger, never()).debug(eq("Current 'letter' {}"), anyString());
|
||||
verify(logger, never()).debug("Replacing all non-abAB characters");
|
||||
verify(logger, never()).debug("Cleaned input string '{}'", "");
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(eq("Cleaned input string '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -219,8 +201,12 @@ public class TestBaconian{
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(eq("Setting input string for decoding '{}'"), anyString());
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Ensuring all 'letters' contain 5 characters");
|
||||
verify(logger, never()).debug(eq("Current 'letter' {}"), anyString());
|
||||
verify(logger, never()).debug("Replacing all non-abAB characters");
|
||||
verify(logger, never()).debug(eq("Cleaned input string '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -237,8 +223,6 @@ public class TestBaconian{
|
||||
verify(logger, times(14)).debug("Encoding lowercase");
|
||||
verify(logger, times(15)).debug(eq("Output letter {}"), anyString());
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", encodedString);
|
||||
verify(logger, times(16)).debug(anyString());
|
||||
verify(logger, times(16)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -256,8 +240,6 @@ public class TestBaconian{
|
||||
verify(logger, times(14)).debug("Decoding lowercase");
|
||||
verify(logger, times(15)).debug(eq("Decoded character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", decodedStringClean);
|
||||
verify(logger, times(16)).debug(anyString());
|
||||
verify(logger, times(16)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestBaseX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-08-22
|
||||
//Modified: 04-16-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -11,13 +11,15 @@ import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidBaseException;
|
||||
@@ -25,8 +27,11 @@ import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestBaseX{
|
||||
@InjectMocks
|
||||
private BaseX cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "A+B@C d\te\nf";
|
||||
@@ -36,14 +41,6 @@ public class TestBaseX{
|
||||
private String encodedString_16 = "41 2B 42 40 43 20 64 9 65 A 66";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new BaseX();
|
||||
logger = mock(Logger.class);
|
||||
BaseX.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new BaseX();
|
||||
@@ -68,8 +65,6 @@ public class TestBaseX{
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
verify(logger, times(1)).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,8 +75,6 @@ public class TestBaseX{
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", "");
|
||||
verify(logger, times(1)).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -164,8 +157,6 @@ public class TestBaseX{
|
||||
|
||||
assertEquals(16, cipher.base);
|
||||
verify(logger, times(1)).debug("Setting base {}", 16);
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,8 +167,6 @@ public class TestBaseX{
|
||||
|
||||
assertEquals(2, cipher.base);
|
||||
verify(logger, never()).debug(eq("Setting base {}"), anyInt());
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -188,8 +177,6 @@ public class TestBaseX{
|
||||
|
||||
assertEquals(2, cipher.base);
|
||||
verify(logger, never()).debug(eq("Setting base {}"), anyInt());
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -256,13 +243,15 @@ public class TestBaseX{
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
verify(logger, times(1)).debug("Resetting fields");
|
||||
verify(logger, times(1)).debug(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_2(){
|
||||
String output = cipher.encode(2, decodedString);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(2, cipher.base);
|
||||
assertEquals(encodedString_2, cipher.outputString);
|
||||
assertEquals(encodedString_2, output);
|
||||
}
|
||||
|
||||
@@ -270,6 +259,9 @@ public class TestBaseX{
|
||||
public void testPracticalEncoding_8(){
|
||||
String output = cipher.encode(8, decodedString);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(8, cipher.base);
|
||||
assertEquals(encodedString_8, cipher.outputString);
|
||||
assertEquals(encodedString_8, output);
|
||||
}
|
||||
|
||||
@@ -277,6 +269,9 @@ public class TestBaseX{
|
||||
public void testPracticalEncoding_10(){
|
||||
String output = cipher.encode(10, decodedString);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(10, cipher.base);
|
||||
assertEquals(encodedString_10, cipher.outputString);
|
||||
assertEquals(encodedString_10, output);
|
||||
}
|
||||
|
||||
@@ -284,6 +279,9 @@ public class TestBaseX{
|
||||
public void testPracticalEncoding_16(){
|
||||
String output = cipher.encode(16, decodedString);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(16, cipher.base);
|
||||
assertEquals(encodedString_16, cipher.outputString);
|
||||
assertEquals(encodedString_16, output);
|
||||
}
|
||||
|
||||
@@ -291,6 +289,9 @@ public class TestBaseX{
|
||||
public void testPracticalEncoding_inputOnly(){
|
||||
String output = cipher.encode(decodedString);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(2, cipher.base);
|
||||
assertEquals(encodedString_2, cipher.outputString);
|
||||
assertEquals(encodedString_2, output);
|
||||
}
|
||||
|
||||
@@ -298,6 +299,9 @@ public class TestBaseX{
|
||||
public void testPracticalDecoding_2(){
|
||||
String output = cipher.decode(2, encodedString_2);
|
||||
|
||||
assertEquals(encodedString_2, cipher.inputString);
|
||||
assertEquals(2, cipher.base);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
}
|
||||
|
||||
@@ -305,6 +309,9 @@ public class TestBaseX{
|
||||
public void testPracticalDecoding_8(){
|
||||
String output = cipher.decode(8, encodedString_8);
|
||||
|
||||
assertEquals(encodedString_8, cipher.inputString);
|
||||
assertEquals(8, cipher.base);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
}
|
||||
|
||||
@@ -312,6 +319,9 @@ public class TestBaseX{
|
||||
public void testPracticalDecoding_10(){
|
||||
String output = cipher.decode(10, encodedString_10);
|
||||
|
||||
assertEquals(encodedString_10, cipher.inputString);
|
||||
assertEquals(10, cipher.base);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
}
|
||||
|
||||
@@ -319,6 +329,9 @@ public class TestBaseX{
|
||||
public void testPracticalDecoding_16(){
|
||||
String output = cipher.decode(16, encodedString_16);
|
||||
|
||||
assertEquals(encodedString_16, cipher.inputString);
|
||||
assertEquals(16, cipher.base);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
}
|
||||
|
||||
@@ -326,6 +339,9 @@ public class TestBaseX{
|
||||
public void testPracticalDecoding_inputOnly(){
|
||||
String output = cipher.decode(encodedString_2);
|
||||
|
||||
assertEquals(encodedString_2, cipher.inputString);
|
||||
assertEquals(2, cipher.base);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestBeaufort.java
|
||||
//Mattrixwv
|
||||
// Created: 02-23-22
|
||||
//Modified: 04-17-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -11,37 +11,34 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestBeaufort{
|
||||
@InjectMocks
|
||||
private Beaufort cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "Message to^encode";
|
||||
private String decodedStringClean = "MESSAGETOENCODE";
|
||||
private String encodedString = "Yageolz rq^ujmdag";
|
||||
private String encodedStringClean = "YAGEOLZRQUJMDAG";
|
||||
private String keyword = "keyword";
|
||||
private String keywordDirty = "Ke*y word";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new Beaufort();
|
||||
logger = mock(Logger.class);
|
||||
Beaufort.logger = logger;
|
||||
}
|
||||
private String keyword = "Ke*y word";
|
||||
private String keywordClean = "KEYWORD";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -142,8 +139,6 @@ public class TestBeaufort{
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString);
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -160,8 +155,6 @@ public class TestBeaufort{
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
verify(logger, times(1)).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,8 +171,6 @@ public class TestBeaufort{
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -196,8 +187,6 @@ public class TestBeaufort{
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -216,8 +205,6 @@ public class TestBeaufort{
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", "");
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -232,34 +219,17 @@ public class TestBeaufort{
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, never()).debug(eq("Cleaned input string '{}'"), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", keyword);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all non-letters");
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", keyword.toUpperCase());
|
||||
verify(logger, times(2)).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword_dirty(){
|
||||
cipher.setKeyword(keywordDirty);
|
||||
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", keywordDirty);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all non-letters");
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", keyword.toUpperCase());
|
||||
verify(logger, times(2)).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", keywordClean);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,8 +243,6 @@ public class TestBeaufort{
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all non-letters");
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", "");
|
||||
verify(logger, times(2)).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -288,8 +256,6 @@ public class TestBeaufort{
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all non-letters");
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", "A");
|
||||
verify(logger, times(2)).debug(anyString());
|
||||
verify(logger, times(2)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -303,17 +269,13 @@ public class TestBeaufort{
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing all non-letters");
|
||||
verify(logger, never()).debug(eq("Cleaned keyword '{}'"), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher = new Beaufort(true, true, true);
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = decodedString;
|
||||
logger = mock(Logger.class);
|
||||
Beaufort.logger = logger;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
@@ -323,17 +285,13 @@ public class TestBeaufort{
|
||||
verify(logger, times(1)).debug("Shifting all letters by 1");
|
||||
verify(logger, times(1)).debug("Encoding with Vigenere");
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", encodedString);
|
||||
verify(logger, times(4)).debug(anyString());
|
||||
verify(logger, times(1)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher = new Beaufort(true, true, true);
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.inputString = decodedString;
|
||||
logger = mock(Logger.class);
|
||||
Beaufort.logger = logger;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
@@ -343,8 +301,6 @@ public class TestBeaufort{
|
||||
verify(logger, times(1)).debug("Shifting all letters by 1");
|
||||
verify(logger, times(1)).debug("Encoding with Vigenere");
|
||||
verify(logger, times(1)).debug("Saving output string '{}'", encodedString);
|
||||
verify(logger, times(4)).debug(anyString());
|
||||
verify(logger, times(1)).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/TestCaesar.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 04-16-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -11,20 +11,25 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestCaesar{
|
||||
@InjectMocks
|
||||
private Caesar cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "The quick brown fox jumps over - the lAzy dog";
|
||||
@@ -34,15 +39,6 @@ public class TestCaesar{
|
||||
private int shift = 23;
|
||||
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new Caesar();
|
||||
logger = mock(Logger.class);
|
||||
Caesar.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new Caesar();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestOneTimePad.java
|
||||
//Mattrixwv
|
||||
// Created: 02-23-22
|
||||
//Modified: 04-17-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
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;
|
||||
@@ -18,15 +17,21 @@ import static org.mockito.Mockito.verify;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestOneTimePad{
|
||||
@InjectMocks
|
||||
private OneTimePad cipher;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.monosubstitution.OneTimePad")
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "Message to^encode";
|
||||
@@ -37,14 +42,6 @@ public class TestOneTimePad{
|
||||
private ArrayList<Integer> offset = new ArrayList<>(Arrays.asList(10, 4, 24, 22, 14, 17, 3, 19, 7, 0, 19, 8, 18, 19, 14, 19, 0, 11, 11, 24, 17, 0, 13, 3, 14, 12));
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new OneTimePad();
|
||||
logger = mock(Logger.class);
|
||||
OneTimePad.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new OneTimePad();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestPorta.java
|
||||
//Mattrixwv
|
||||
// Created: 02-28-22
|
||||
//Modified: 04-17-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -12,21 +12,26 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestPorta{
|
||||
@InjectMocks
|
||||
private Porta cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "Message to^encode";
|
||||
@@ -34,14 +39,7 @@ public class TestPorta{
|
||||
private String encodedString = "Rtghuos bm^qcwgrw";
|
||||
private String encodedStringClean = "RTGHUOSBMQCWGRW";
|
||||
private String keyword = "keyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new Porta();
|
||||
logger = mock(Logger.class);
|
||||
Porta.logger = logger;
|
||||
}
|
||||
private String keywordDirty = "Ke yw*ord";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -103,6 +101,17 @@ public class TestPorta{
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", keyword.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword_dirty(){
|
||||
cipher.setKeyword(keywordDirty);
|
||||
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", keywordDirty);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all non-letters");
|
||||
verify(logger, times(1)).debug("Cleaned keyword '{}'", keyword.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyword_blank(){
|
||||
assertThrows(InvalidKeywordException.class, () -> {
|
||||
@@ -136,8 +145,10 @@ public class TestPorta{
|
||||
});
|
||||
|
||||
assertEquals("", cipher.keyword);
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(eq("Original keyword '{}'"), anyString());
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing all non-letters");
|
||||
verify(logger, never()).debug(eq("Cleaned keyword '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -244,8 +255,11 @@ public class TestPorta{
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
verify(logger, never()).debug(anyString());
|
||||
verify(logger, never()).debug(eq("Original input string {}"), anyString());
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, never()).debug(eq("Cleaned input string '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestSubstitution.java
|
||||
//Mattrixwv
|
||||
// Created: 02-22-22
|
||||
//Modified: 04-18-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -12,21 +12,26 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestSubstitution{
|
||||
@InjectMocks
|
||||
private Substitution cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "Message to^encode";
|
||||
@@ -38,15 +43,9 @@ public class TestSubstitution{
|
||||
private String encodedStringAlNum = "Oguucig vq^gpeqfg 876";
|
||||
private String encodedStringAlNumClean = "OGUUCIGVQGPEQFG";
|
||||
private String keyword = "cdefghijklmnopqrstuvwxyzab";
|
||||
private String keywordClean = "CDEFGHIJKLMNOPQRSTUVWXYZAB";
|
||||
private String keywordAlNum = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new Substitution();
|
||||
logger = mock(Logger.class);
|
||||
Substitution.logger = logger;
|
||||
}
|
||||
private String keywordAlNumClean = "CDEFGHIJKLMNOPQRSTUVWXYZAB9876543210";
|
||||
|
||||
|
||||
@Test
|
||||
@@ -98,33 +97,33 @@ public class TestSubstitution{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey(){
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original key '{}'", keyword);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Ensuring there are no duplicate mappings");
|
||||
verify(logger, times(1)).debug("Ensuring there are only letters in the key");
|
||||
verify(logger, never()).debug("Ensuring there are only alpha-numeric characters in the key");
|
||||
verify(logger, times(1)).debug("Cleaned key '{}'", keyword.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned key '{}'", keywordClean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey_alNum(){
|
||||
public void testSetKeyword_alNum(){
|
||||
cipher.setKeyword(keywordAlNum);
|
||||
|
||||
assertEquals(keywordAlNum.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original key '{}'", keywordAlNum);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Ensuring there are no duplicate mappings");
|
||||
verify(logger, never()).debug("Ensuring there are only letters in the key");
|
||||
verify(logger, times(1)).debug("Ensuring there are only alpha-numeric characters in the key");
|
||||
verify(logger, times(1)).debug("Cleaned key '{}'", keywordAlNum.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned key '{}'", keywordAlNumClean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey_duplicate(){
|
||||
public void testSetKeyword_duplicate(){
|
||||
assertThrows(InvalidKeywordException.class, () -> {
|
||||
cipher.setKeyword("ABA");
|
||||
});
|
||||
@@ -139,7 +138,7 @@ public class TestSubstitution{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey_invalidLetter(){
|
||||
public void testSetKeyword_invalidLetter(){
|
||||
assertThrows(InvalidKeywordException.class, () ->{
|
||||
cipher.setKeyword("abcdefghijklmnop1rstuvwxyz");
|
||||
});
|
||||
@@ -154,7 +153,7 @@ public class TestSubstitution{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey_invalidAlNum(){
|
||||
public void testSetKeyword_invalidAlNum(){
|
||||
assertThrows(InvalidKeywordException.class, () -> {
|
||||
cipher.setKeyword("abcdefghijklmnop^rstuvwxyz0123456789");
|
||||
});
|
||||
@@ -169,7 +168,7 @@ public class TestSubstitution{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey_invalidLength(){
|
||||
public void testSetKeyword_invalidLength(){
|
||||
assertThrows(InvalidKeywordException.class, () -> {
|
||||
cipher.setKeyword("AB");
|
||||
});
|
||||
@@ -184,7 +183,7 @@ public class TestSubstitution{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKey_null(){
|
||||
public void testSetKeyword_null(){
|
||||
assertThrows(InvalidKeywordException.class, () -> {
|
||||
cipher.setKeyword(null);
|
||||
});
|
||||
@@ -304,7 +303,7 @@ public class TestSubstitution{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.inputString = decodedStringAlNum;
|
||||
cipher.keyword = keywordAlNum.toUpperCase();
|
||||
cipher.keyword = keywordAlNumClean;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
@@ -324,7 +323,7 @@ public class TestSubstitution{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.inputString = encodedStringAlNum;
|
||||
cipher.keyword = keywordAlNum.toUpperCase();
|
||||
cipher.keyword = keywordAlNumClean;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
@@ -370,7 +369,7 @@ public class TestSubstitution{
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
}
|
||||
@@ -382,7 +381,7 @@ public class TestSubstitution{
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
}
|
||||
@@ -394,7 +393,7 @@ public class TestSubstitution{
|
||||
String output = cipher.encode(keywordAlNum, decodedStringAlNum);
|
||||
|
||||
assertEquals(decodedStringAlNum, cipher.inputString);
|
||||
assertEquals(keywordAlNum.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
||||
assertEquals(encodedStringAlNum, cipher.outputString);
|
||||
assertEquals(encodedStringAlNum, output);
|
||||
}
|
||||
@@ -406,7 +405,7 @@ public class TestSubstitution{
|
||||
String output = cipher.encode(keywordAlNum, decodedStringAlNum);
|
||||
|
||||
assertEquals(decodedStringAlNumClean, cipher.inputString);
|
||||
assertEquals(keywordAlNum.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
||||
assertEquals(encodedStringAlNumClean, cipher.outputString);
|
||||
assertEquals(encodedStringAlNumClean, output);
|
||||
}
|
||||
@@ -418,7 +417,7 @@ public class TestSubstitution{
|
||||
String output = cipher.encode(keyword, decodedStringAlNum);
|
||||
|
||||
assertEquals(decodedStringAlNum, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedString + " 123", cipher.outputString);
|
||||
assertEquals(encodedString + " 123", output);
|
||||
}
|
||||
@@ -430,7 +429,7 @@ public class TestSubstitution{
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
}
|
||||
@@ -442,7 +441,7 @@ public class TestSubstitution{
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
}
|
||||
@@ -454,7 +453,7 @@ public class TestSubstitution{
|
||||
String output = cipher.decode(keywordAlNum, encodedStringAlNum);
|
||||
|
||||
assertEquals(encodedStringAlNum, cipher.inputString);
|
||||
assertEquals(keywordAlNum.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
||||
assertEquals(decodedStringAlNum, cipher.outputString);
|
||||
assertEquals(decodedStringAlNum, output);
|
||||
}
|
||||
@@ -466,7 +465,7 @@ public class TestSubstitution{
|
||||
String output = cipher.decode(keywordAlNum, encodedStringAlNum);
|
||||
|
||||
assertEquals(encodedStringAlNumClean, cipher.inputString);
|
||||
assertEquals(keywordAlNum.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordAlNumClean, cipher.keyword);
|
||||
assertEquals(decodedStringAlNumClean, cipher.outputString);
|
||||
assertEquals(decodedStringAlNumClean, output);
|
||||
}
|
||||
@@ -478,7 +477,7 @@ public class TestSubstitution{
|
||||
String output = cipher.decode(keyword, encodedString + " 123");
|
||||
|
||||
assertEquals(encodedString + " 123", cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedString + " 123", cipher.outputString);
|
||||
assertEquals(decodedString + " 123", output);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestVigenere.java
|
||||
//Mattrixwv
|
||||
// Created: 07-25-21
|
||||
//Modified: 04-18-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -20,34 +19,33 @@ import static org.mockito.Mockito.verify;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestVigenere{
|
||||
@InjectMocks
|
||||
private Vigenere cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String inputString = "MeSsage to^encode";
|
||||
private String inputStringClean = "MESSAGETOENCODE";
|
||||
private String outputString = "WiQooxh ds^cjqfgo";
|
||||
private String outputStringClean = "WIQOOXHDSCJQFGO";
|
||||
private String keyword = "keyword";
|
||||
private String keyword = "ke yw*ord";
|
||||
private String keywordClean = "KEYWORD";
|
||||
private ArrayList<Integer> offset = new ArrayList<>(List.of(10, 4, 24, 22, 14, 17, 3));
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new Vigenere();
|
||||
logger = mock(Logger.class);
|
||||
Vigenere.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new Vigenere();
|
||||
@@ -102,11 +100,11 @@ public class TestVigenere{
|
||||
|
||||
@Test
|
||||
public void testSetOffset(){
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
|
||||
cipher.setOffset();
|
||||
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(offset, cipher.offset);
|
||||
verify(logger, times(1)).debug("Setting offset array from keyword");
|
||||
verify(logger, times(1)).debug("Offset {}", offset);
|
||||
@@ -117,7 +115,7 @@ public class TestVigenere{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.offset = offset;
|
||||
|
||||
cipher.setInputString(inputString);
|
||||
@@ -135,7 +133,7 @@ public class TestVigenere{
|
||||
cipher.preserveCapitals = false;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.offset = offset;
|
||||
|
||||
cipher.setInputString(inputString);
|
||||
@@ -153,7 +151,7 @@ public class TestVigenere{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.offset = offset;
|
||||
|
||||
cipher.setInputString(inputString);
|
||||
@@ -171,7 +169,7 @@ public class TestVigenere{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.offset = offset;
|
||||
|
||||
cipher.setInputString(inputString);
|
||||
@@ -189,7 +187,7 @@ public class TestVigenere{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.offset = offset;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -209,7 +207,7 @@ public class TestVigenere{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.offset = offset;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -228,12 +226,12 @@ public class TestVigenere{
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(offset, cipher.offset);
|
||||
verify(logger, times(1)).debug("Original keyword '{}'", keyword);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing all non-letter characters");
|
||||
verify(logger, times(1)).debug("Clean keyword '{}'", keyword.toUpperCase());
|
||||
verify(logger, times(1)).debug("Clean keyword '{}'", keywordClean);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -270,7 +268,7 @@ public class TestVigenere{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.inputString = inputString;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.offset = offset;
|
||||
|
||||
cipher.encode();
|
||||
@@ -292,7 +290,7 @@ public class TestVigenere{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.inputString = outputString;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.offset = offset;
|
||||
|
||||
cipher.decode();
|
||||
@@ -344,7 +342,7 @@ public class TestVigenere{
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
|
||||
assertEquals(inputString, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(offset, cipher.offset);
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(outputString, output);
|
||||
@@ -357,7 +355,7 @@ public class TestVigenere{
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
|
||||
assertEquals(inputStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(offset, cipher.offset);
|
||||
assertEquals(outputStringClean, cipher.outputString);
|
||||
assertEquals(outputStringClean, output);
|
||||
@@ -370,7 +368,7 @@ public class TestVigenere{
|
||||
String output = cipher.decode(keyword, outputString);
|
||||
|
||||
assertEquals(outputString, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(offset, cipher.offset);
|
||||
assertEquals(inputString, cipher.outputString);
|
||||
assertEquals(inputString, output);
|
||||
@@ -383,7 +381,7 @@ public class TestVigenere{
|
||||
String output = cipher.decode(keyword, outputString);
|
||||
|
||||
assertEquals(outputStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(offset, cipher.offset);
|
||||
assertEquals(inputStringClean, cipher.outputString);
|
||||
assertEquals(inputStringClean, output);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestBifid.java
|
||||
//Mattrixwv
|
||||
// Created: 03-03-22
|
||||
//Modified: 04-23-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -13,21 +13,26 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestBifid{
|
||||
@InjectMocks
|
||||
private Bifid cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Test
|
||||
private String inputString = "Message to^encode";
|
||||
@@ -38,14 +43,6 @@ public class TestBifid{
|
||||
private String keywordClean = "KEYWORDABCFGHILMNPQSTUVXZ";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new Bifid();
|
||||
logger = mock(Logger.class);
|
||||
Bifid.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new Bifid();
|
||||
@@ -121,7 +118,6 @@ public class TestBifid{
|
||||
});
|
||||
|
||||
verify(logger, never()).debug(eq("Setting keyword '{}'"), anyString());
|
||||
verify(logger, never()).debug(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//Mattrixwv/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestColumnar.java
|
||||
//Mattrixwv
|
||||
// Created: 01-16-22
|
||||
//Modified: 04-26-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -21,8 +20,11 @@ import static org.mockito.Mockito.verify;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
@@ -30,8 +32,11 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestColumnar{
|
||||
@InjectMocks
|
||||
private Columnar cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "Message to*encode";
|
||||
@@ -42,7 +47,8 @@ public class TestColumnar{
|
||||
private String encodedStringPadingAdded = "Edxeoxmte ac*xgoxsnxsex"; //When padding is added to outputString for decoding
|
||||
private String encodedStringPadded = "Edxeoxm te*acxgoxsnxsex"; //When padding is left in outputString
|
||||
private String encodedStringClean = "EDXEOXMTEACXGOXSNXSEX";
|
||||
private String keyword = "keyword";
|
||||
private String keyword = "ke yw*ord";
|
||||
private String keywordClean = "KEYWORD";
|
||||
private ArrayList<ArrayList<Character>> encodeGrid = new ArrayList<>(
|
||||
List.of(
|
||||
new ArrayList<>(
|
||||
@@ -77,14 +83,6 @@ public class TestColumnar{
|
||||
);
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new Columnar();
|
||||
logger = mock(Logger.class);
|
||||
Columnar.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new Columnar();
|
||||
@@ -257,7 +255,7 @@ public class TestColumnar{
|
||||
@Test
|
||||
public void testCreateGridEncode(){
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
|
||||
cipher.createGridEncode();
|
||||
|
||||
@@ -268,7 +266,7 @@ public class TestColumnar{
|
||||
@Test
|
||||
public void testCreateGridDecode(){
|
||||
cipher.inputString = encodedStringPadingAdded;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
|
||||
cipher.createGridDecode();
|
||||
|
||||
@@ -281,7 +279,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
@@ -301,7 +299,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = false;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.characterToAdd = 'X';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
@@ -321,7 +319,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
@@ -341,7 +339,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
cipher.keyword = keyword;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
@@ -427,7 +425,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
@@ -446,7 +444,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringDecode("Message to encod");
|
||||
@@ -465,7 +463,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = false;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.characterToAdd = 'X';
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
@@ -484,7 +482,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
@@ -503,7 +501,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
@@ -522,7 +520,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -543,7 +541,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -564,7 +562,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
@@ -584,7 +582,7 @@ public class TestColumnar{
|
||||
public void testCreateOutputStringFromColumns(){
|
||||
cipher.removePadding = true;
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = decodeGrid;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
@@ -603,7 +601,7 @@ public class TestColumnar{
|
||||
public void testCreateOutputStringFromColumns_padding(){
|
||||
cipher.removePadding = false;
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = decodeGrid;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
@@ -622,7 +620,7 @@ public class TestColumnar{
|
||||
public void testCreateOutputStringFromRows(){
|
||||
cipher.removePadding = false;
|
||||
cipher.inputString = encodedStringPadded;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = encodeGrid;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
@@ -645,7 +643,7 @@ public class TestColumnar{
|
||||
public void testCreateOuputStringFromRows_removePadding(){
|
||||
cipher.removePadding = true;
|
||||
cipher.inputString = encodedStringPadingAdded;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = encodeGrid;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
@@ -668,9 +666,9 @@ public class TestColumnar{
|
||||
public void testSetKeyword(){
|
||||
cipher.setKeyword(keyword);
|
||||
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
verify(logger, times(1)).debug("Original keyword {}", keyword);
|
||||
verify(logger, times(1)).debug("Cleaned keyword {}", keyword.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned keyword {}", keywordClean);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -732,7 +730,7 @@ public class TestColumnar{
|
||||
public void testGetKeywordAlphaLocations(){
|
||||
ArrayList<Integer> alphaLocations = new ArrayList<>(List.of(6, 1, 0, 4, 5, 3, 2));
|
||||
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
|
||||
ArrayList<Integer> returnedLocations = cipher.getKeywordAlphaLocations();
|
||||
|
||||
@@ -745,7 +743,7 @@ public class TestColumnar{
|
||||
public void testGetKeywordOriginalLocations(){
|
||||
ArrayList<Integer> orderedLocations = new ArrayList<>(List.of(2, 1, 6, 5, 3, 4, 0));
|
||||
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
|
||||
ArrayList<Integer> returnedLocations = cipher.getKeywordOriginalLocations();
|
||||
|
||||
@@ -785,7 +783,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.removePadding = true;
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
@@ -804,7 +802,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.removePadding = false;
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
@@ -823,7 +821,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.removePadding = true;
|
||||
cipher.inputString = encodedStringPadingAdded;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
@@ -842,7 +840,7 @@ public class TestColumnar{
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.removePadding = false;
|
||||
cipher.inputString = encodedStringPadded;
|
||||
cipher.keyword = keyword.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.charsAdded = 6;
|
||||
cipher.characterToAdd = 'x';
|
||||
|
||||
@@ -891,7 +889,7 @@ public class TestColumnar{
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
}
|
||||
@@ -903,7 +901,7 @@ public class TestColumnar{
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedStringPadded, cipher.outputString);
|
||||
assertEquals(encodedStringPadded, output);
|
||||
}
|
||||
@@ -915,7 +913,7 @@ public class TestColumnar{
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
}
|
||||
@@ -927,7 +925,7 @@ public class TestColumnar{
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
|
||||
assertEquals(encodedStringPadingAdded, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
}
|
||||
@@ -939,7 +937,7 @@ public class TestColumnar{
|
||||
String output = cipher.decode(keyword, encodedStringPadded);
|
||||
|
||||
assertEquals(encodedStringPadded, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedStringPadded, cipher.outputString);
|
||||
assertEquals(decodedStringPadded, output);
|
||||
}
|
||||
@@ -951,7 +949,7 @@ public class TestColumnar{
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(keyword.toUpperCase(), cipher.keyword);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamjava/polySubstitution/TestHill.java
|
||||
//Mattrixwv
|
||||
// Created: 01-31-22
|
||||
//Modified: 04-28-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -14,15 +14,17 @@ import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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 java.util.ArrayList;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
@@ -31,8 +33,11 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeyException;
|
||||
import com.mattrixwv.matrix.ModMatrix;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestHill{
|
||||
@InjectMocks
|
||||
private Hill cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Fields
|
||||
private String decodedString = "Message to^encoded";
|
||||
@@ -44,14 +49,6 @@ public class TestHill{
|
||||
private ModMatrix key = new ModMatrix(keyArray, 26);
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new Hill();
|
||||
logger = mock(Logger.class);
|
||||
Hill.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new Hill();
|
||||
@@ -152,7 +149,7 @@ public class TestHill{
|
||||
verify(logger, times(1)).debug("Testing mod");
|
||||
verify(logger, times(1)).debug("Testing square");
|
||||
verify(logger, times(1)).debug("Testing invertable");
|
||||
verify(logger, times(1)).debug("key = {}", key);
|
||||
verify(logger, times(1)).debug("key\n{}", key);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -168,7 +165,7 @@ public class TestHill{
|
||||
verify(logger, times(1)).debug("Testing mod");
|
||||
verify(logger, never()).debug("Testing square");
|
||||
verify(logger, never()).debug("Testing invertable");
|
||||
verify(logger, never()).debug(eq("key = {}"), any(ModMatrix.class));
|
||||
verify(logger, never()).debug(eq("key\n{}"), any(ModMatrix.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -184,7 +181,7 @@ public class TestHill{
|
||||
verify(logger, times(1)).debug("Testing mod");
|
||||
verify(logger, times(1)).debug("Testing square");
|
||||
verify(logger, never()).debug("Testing invertable");
|
||||
verify(logger, never()).debug(eq("key = {}"), any(ModMatrix.class));
|
||||
verify(logger, never()).debug(eq("key\n{}"), any(ModMatrix.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -200,7 +197,7 @@ public class TestHill{
|
||||
verify(logger, times(1)).debug("Testing mod");
|
||||
verify(logger, times(1)).debug("Testing square");
|
||||
verify(logger, times(1)).debug("Testing invertable");
|
||||
verify(logger, never()).debug(eq("key = {}"), any(ModMatrix.class));
|
||||
verify(logger, never()).debug(eq("key\n{}"), any(ModMatrix.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/polysubstitution/TestLargePolybiusSquare.java
|
||||
//Mattrixwv
|
||||
// Created: 04-21-23
|
||||
//Modified: 04-21-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -13,28 +13,33 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestLargePolybiusSquare{
|
||||
@InjectMocks
|
||||
private LargePolybiusSquare cipher;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.polysubstitution.LargePolybiusSquare")
|
||||
private Logger logger;
|
||||
//Variables
|
||||
private String decodedString = "Message to^encode";
|
||||
private String decodedStringClean = "MESSAGETOENCODE";
|
||||
private String encodedString = "35124343222612 4415^123624152112";
|
||||
private String encodedStringClean = "31 15 41 41 11 21 15 42 33 15 32 13 33 14 15";
|
||||
private String keyword = "keyword";
|
||||
private String keyword = "ke yw*ord";
|
||||
private String keywordClean = "KEYWORDABCFGHIJLMNPQSTUVXZ0123456789";
|
||||
private String keywordBlank = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
private char[][] grid = {
|
||||
@@ -55,14 +60,6 @@ public class TestLargePolybiusSquare{
|
||||
};
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new LargePolybiusSquare();
|
||||
logger = mock(Logger.class);
|
||||
LargePolybiusSquare.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new LargePolybiusSquare();
|
||||
|
||||
@@ -1,58 +1,243 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/TestMorse.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-28-21
|
||||
//Modified: 07-09-22
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestMorse{
|
||||
@InjectMocks
|
||||
private Morse cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Fields
|
||||
private String inputString = "Message to^encode123";
|
||||
private String inputStringClean = "MESSAGETOENCODE123";
|
||||
private String outputString = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor(){
|
||||
cipher = new Morse();
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputStringEncode(){
|
||||
cipher.setInputStringEncode(inputString);
|
||||
|
||||
assertEquals(inputStringClean, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", inputString);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace and symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputStringClean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputStringEncode_blank(){
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringEncode("");
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", "");
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace and symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputStringEncode_blankClean(){
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringEncode("*&^");
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", "*&^");
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace and symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputStringEncode_null(){
|
||||
String nullString = null;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringEncode(null);
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", nullString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace and symbols");
|
||||
verify(logger, never()).debug(eq("Cleaned input string '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputStringDecode(){
|
||||
cipher.setInputStringDecode(outputString);
|
||||
|
||||
assertEquals(outputString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", outputString);
|
||||
verify(logger, times(1)).debug("Checking for invalid characters");
|
||||
verify(logger, times(1)).debug("Saving");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputStringDecode_invalid(){
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringDecode("*");
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", "*");
|
||||
verify(logger, times(1)).debug("Checking for invalid characters");
|
||||
verify(logger, never()).debug("Saving");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputStringDecode_blank(){
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringDecode("");
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", "");
|
||||
verify(logger, times(1)).debug("Checking for invalid characters");
|
||||
verify(logger, never()).debug("Saving");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputStringDecode_null(){
|
||||
String nullString = null;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringDecode(null);
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", nullString);
|
||||
verify(logger, never()).debug("Checking for invalid characters");
|
||||
verify(logger, never()).debug("Saving");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
Morse cipher = new Morse();
|
||||
cipher.inputString = inputStringClean;
|
||||
|
||||
//Test 1
|
||||
String input = "sos";
|
||||
String correctOutput = "... --- ...";
|
||||
String output = cipher.encode(input);
|
||||
assertEquals(correctOutput, output);
|
||||
cipher.encode();
|
||||
|
||||
//Test 2
|
||||
input = "MORSE, CODE";
|
||||
correctOutput = "-- --- .-. ... . -.-. --- -.. .";
|
||||
output = cipher.encode(input);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test 3
|
||||
input = "1.23 987";
|
||||
correctOutput = ".---- ..--- ...-- ----. ---.. --...";
|
||||
output = cipher.encode(input);
|
||||
assertEquals(correctOutput, output);
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(18)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(15)).debug("Appending letter");
|
||||
verify(logger, times(3)).debug("Appending number");
|
||||
verify(logger, times(1)).debug("Saving encoded string '{}'", outputString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode_invalid(){
|
||||
cipher.inputString = "*";
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.encode();
|
||||
});
|
||||
|
||||
assertEquals("", cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(1)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, never()).debug("Appending letter");
|
||||
verify(logger, never()).debug("Appending number");
|
||||
verify(logger, never()).debug("Saving encoded string '{}'", outputString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
Morse cipher = new Morse();
|
||||
cipher.inputString = outputString;
|
||||
|
||||
//Test 1
|
||||
String input = "... --- ...";
|
||||
String correctOutput = "SOS";
|
||||
String output = cipher.decode(input);
|
||||
assertEquals(correctOutput, output);
|
||||
cipher.decode();
|
||||
|
||||
//Test 2
|
||||
input = "-- --- .-. ... . -.-. --- -.. .";
|
||||
correctOutput = "MORSECODE";
|
||||
output = cipher.decode(input);
|
||||
assertEquals(correctOutput, output);
|
||||
assertEquals(inputStringClean, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(18)).debug(eq("Working letter {}"), anyString());
|
||||
verify(logger, times(18)).debug(eq("Decoded letter {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Saving decoded string '{}'", inputStringClean);
|
||||
}
|
||||
|
||||
//Test 3
|
||||
input = ".---- ..--- ...-- ----. ---.. --...";
|
||||
correctOutput = "123987";
|
||||
output = cipher.decode(input);
|
||||
assertEquals(correctOutput, output);
|
||||
@Test
|
||||
public void testDecode_invalid(){
|
||||
cipher.inputString = "A";
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.decode();
|
||||
});
|
||||
|
||||
assertEquals("", cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(1)).debug(eq("Working letter {}"), anyString());
|
||||
verify(logger, never()).debug(eq("Decoded letter {}"), anyChar());
|
||||
verify(logger, never()).debug(eq("Saving decoded string '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.outputString = outputString;
|
||||
|
||||
assertEquals(inputString, cipher.getInputString());
|
||||
assertEquals(outputString, cipher.getOutputString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.outputString = outputString;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
verify(logger, times(1)).debug("Resetting");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncode(){
|
||||
String output = cipher.encode(inputString);
|
||||
|
||||
assertEquals(inputStringClean, cipher.inputString);
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(outputString, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecode(){
|
||||
String output = cipher.decode(outputString);
|
||||
|
||||
assertEquals(outputString, cipher.inputString);
|
||||
assertEquals(inputStringClean, cipher.outputString);
|
||||
assertEquals(inputStringClean, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/TestPlayfair.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-30-21
|
||||
//Modified: 04-28-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -15,13 +15,15 @@ import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
@@ -30,15 +32,18 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.Playfair.CharLocation;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestPlayfair{
|
||||
@InjectMocks
|
||||
private Playfair cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Fields
|
||||
private String inputString = "Hide the gold in - the@tree+stump";
|
||||
private String inputStringPadded = "Hide the gold in - the@trexe+stump";
|
||||
private String inputStringClean = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
private String outputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
private String outputStringClean = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
private String decodedString = "Hide the gold in - the@tree+stump";
|
||||
private String decodedStringPadded = "Hide the gold in - the@trexe+stump";
|
||||
private String decodedStringClean = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
private String encodedString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
private String encodedStringClean = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
private String keyword = "Play-fair@Exam ple";
|
||||
private String keywordClean = "PLAYFIREXMBCDGHKNOQSTUVWZ";
|
||||
private char[][] grid = new char[][]{
|
||||
@@ -50,14 +55,6 @@ public class TestPlayfair{
|
||||
};
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new Playfair();
|
||||
logger = mock(Logger.class);
|
||||
Playfair.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new Playfair();
|
||||
@@ -424,11 +421,11 @@ public class TestPlayfair{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputString(inputString, true);
|
||||
cipher.setInputString(decodedString, true);
|
||||
|
||||
assertEquals(inputStringPadded, cipher.inputString);
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", inputString);
|
||||
verify(logger, times(1)).debug("Original input string {}", decodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
@@ -441,11 +438,11 @@ public class TestPlayfair{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.doubled = 'X';
|
||||
|
||||
cipher.setInputString(inputString, true);
|
||||
cipher.setInputString(decodedString, true);
|
||||
|
||||
assertEquals(inputStringPadded.toUpperCase(), cipher.inputString);
|
||||
assertEquals(decodedStringPadded.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", inputString);
|
||||
verify(logger, times(1)).debug("Original input string {}", decodedString);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
@@ -458,11 +455,11 @@ public class TestPlayfair{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputString(inputString, true);
|
||||
cipher.setInputString(decodedString, true);
|
||||
|
||||
assertEquals(inputStringPadded.replaceAll("\\s", ""), cipher.inputString);
|
||||
assertEquals(decodedStringPadded.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", inputString);
|
||||
verify(logger, times(1)).debug("Original input string {}", decodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
@@ -475,11 +472,11 @@ public class TestPlayfair{
|
||||
cipher.preserveSymbols = false;
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputString(inputString, true);
|
||||
cipher.setInputString(decodedString, true);
|
||||
|
||||
assertEquals(inputStringPadded.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
assertEquals(decodedStringPadded.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", inputString);
|
||||
verify(logger, times(1)).debug("Original input string {}", decodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
@@ -511,15 +508,15 @@ public class TestPlayfair{
|
||||
cipher.preserveSymbols = true;
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputString(outputString, false);
|
||||
cipher.setInputString(encodedString, false);
|
||||
|
||||
assertEquals(outputString, cipher.inputString);
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", outputString);
|
||||
verify(logger, times(1)).debug("Original input string {}", encodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", outputString);
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", encodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -530,16 +527,16 @@ public class TestPlayfair{
|
||||
cipher.doubled = 'x';
|
||||
|
||||
assertThrows(InvalidCharacterException.class, () -> {
|
||||
cipher.setInputString(outputString + cipher.replaced, false);
|
||||
cipher.setInputString(encodedString + cipher.replaced, false);
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", outputString + Character.toString(cipher.replaced));
|
||||
verify(logger, times(1)).debug("Original input string {}", encodedString + Character.toString(cipher.replaced));
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, never()).debug("Clean input string '{}'", outputString);
|
||||
verify(logger, never()).debug("Clean input string '{}'", encodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -550,16 +547,16 @@ public class TestPlayfair{
|
||||
cipher.doubled = 'x';
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString(outputString + "a", false);
|
||||
cipher.setInputString(encodedString + "a", false);
|
||||
});
|
||||
|
||||
assertEquals(outputString + "a", cipher.inputString);
|
||||
assertEquals(encodedString + "a", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string");
|
||||
verify(logger, times(1)).debug("Original input string {}", outputString + "a");
|
||||
verify(logger, times(1)).debug("Original input string {}", encodedString + "a");
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", outputString + "a");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", encodedString + "a");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -606,48 +603,48 @@ public class TestPlayfair{
|
||||
public void testSetInputStringEncode(){
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputStringEncode(inputString);
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
|
||||
assertEquals(inputStringPadded, cipher.inputString);
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Cleaning up input string for encoding");
|
||||
verify(logger, times(1)).debug("Replacing all {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(13)).debug(eq("Starting at character {}"), anyInt());
|
||||
verify(logger, times(13)).debug(eq("Adding to clean input: {} {} {} {}"), any(StringBuilder.class), anyChar(), any(StringBuilder.class), anyChar());
|
||||
verify(logger, times(1)).debug("Checking odd characters");
|
||||
verify(logger, never()).debug("Adding final character to make even");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputStringPadded);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputStringEncode_odd(){
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputStringEncode(inputStringPadded + 'a');
|
||||
cipher.setInputStringEncode(decodedStringPadded + 'a');
|
||||
|
||||
assertEquals(inputStringPadded + "ax", cipher.inputString);
|
||||
assertEquals(decodedStringPadded + "ax", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Cleaning up input string for encoding");
|
||||
verify(logger, times(1)).debug("Replacing all {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(14)).debug(eq("Starting at character {}"), anyInt());
|
||||
verify(logger, times(14)).debug(eq("Adding to clean input: {} {} {} {}"), any(StringBuilder.class), anyChar(), any(StringBuilder.class), anyChar());
|
||||
verify(logger, times(1)).debug("Checking odd characters");
|
||||
verify(logger, times(1)).debug("Adding final character to make even");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputStringPadded + "ax");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded + "ax");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInputString_oddEndSymbol(){
|
||||
cipher.doubled = 'x';
|
||||
|
||||
cipher.setInputStringEncode(inputStringPadded + "a*");
|
||||
cipher.setInputStringEncode(decodedStringPadded + "a*");
|
||||
|
||||
assertEquals(inputStringPadded + "a*x", cipher.inputString);
|
||||
assertEquals(decodedStringPadded + "a*x", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Cleaning up input string for encoding");
|
||||
verify(logger, times(1)).debug("Replacing all {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(14)).debug(eq("Starting at character {}"), anyInt());
|
||||
verify(logger, times(14)).debug(eq("Adding to clean input: {} {} {} {}"), any(StringBuilder.class), anyChar(), any(StringBuilder.class), anyChar());
|
||||
verify(logger, times(1)).debug("Checking odd characters");
|
||||
verify(logger, times(1)).debug("Adding final character to make even");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputStringPadded + "a*x");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded + "a*x");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -655,26 +652,26 @@ public class TestPlayfair{
|
||||
cipher.doubled = 'x';
|
||||
cipher.replacer = 'i';
|
||||
|
||||
cipher.setInputStringEncode(inputStringPadded + 'x');
|
||||
cipher.setInputStringEncode(decodedStringPadded + 'x');
|
||||
|
||||
assertEquals(inputStringPadded + "xi", cipher.inputString);
|
||||
assertEquals(decodedStringPadded + "xi", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Cleaning up input string for encoding");
|
||||
verify(logger, times(1)).debug("Replacing all {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(14)).debug(eq("Starting at character {}"), anyInt());
|
||||
verify(logger, times(14)).debug(eq("Adding to clean input: {} {} {} {}"), any(StringBuilder.class), anyChar(), any(StringBuilder.class), anyChar());
|
||||
verify(logger, times(1)).debug("Checking odd characters");
|
||||
verify(logger, times(1)).debug("Adding final character to make even");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputStringPadded + "xi");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringPadded + "xi");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreparedInputString(){
|
||||
cipher.inputString = inputStringPadded;
|
||||
cipher.inputString = decodedStringPadded;
|
||||
|
||||
String output = cipher.getPreparedInputString();
|
||||
assertEquals(inputStringClean, output);
|
||||
assertEquals(decodedStringClean, output);
|
||||
verify(logger, times(1)).debug("Getting input string ready for encoding");
|
||||
verify(logger, times(1)).debug("Prepared string '{}'", inputStringClean);
|
||||
verify(logger, times(1)).debug("Prepared string '{}'", decodedStringClean);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -768,28 +765,28 @@ public class TestPlayfair{
|
||||
|
||||
@Test
|
||||
public void testAddCharactersToCleanString(){
|
||||
cipher.inputString = inputStringPadded;
|
||||
cipher.inputString = decodedStringPadded;
|
||||
|
||||
cipher.addCharactersToCleanString(outputStringClean);
|
||||
cipher.addCharactersToCleanString(encodedStringClean);
|
||||
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string");
|
||||
verify(logger, times(34)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Appending uppercase");
|
||||
verify(logger, times(25)).debug("Appending lowercase");
|
||||
verify(logger, times(8)).debug("Appending symbol");
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", outputString);
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", encodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = inputStringPadded;
|
||||
cipher.inputString = decodedStringPadded;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(13)).debug(eq("Letters {} {}"), anyChar(), anyChar());
|
||||
verify(logger, times(2)).debug("Row encoding");
|
||||
@@ -800,13 +797,13 @@ public class TestPlayfair{
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.inputString = outputString;
|
||||
cipher.inputString = encodedString;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(inputStringPadded, cipher.outputString);
|
||||
assertEquals(decodedStringPadded, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(13)).debug(eq("Letters {} {}"), anyChar(), anyChar());
|
||||
verify(logger, times(2)).debug("Row decoding");
|
||||
@@ -817,8 +814,8 @@ public class TestPlayfair{
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.outputString = outputString;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.grid = grid;
|
||||
|
||||
@@ -833,13 +830,13 @@ public class TestPlayfair{
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.outputString = outputString;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.grid = grid;
|
||||
|
||||
assertEquals(inputString, cipher.getInputString());
|
||||
assertEquals(outputString, cipher.getOutputString());
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals(keyword, cipher.getKeyword());
|
||||
assertEquals("[P L A Y F]\n[I R E X M]\n[B C D G H]\n[K N O Q S]\n[T U V W Z]", cipher.getGrid());
|
||||
assertEquals('J', cipher.getReplaced());
|
||||
@@ -852,12 +849,12 @@ public class TestPlayfair{
|
||||
public void testPracticalEncode(){
|
||||
cipher = new Playfair(true, true, true);
|
||||
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
|
||||
assertEquals(inputStringPadded, cipher.inputString);
|
||||
assertEquals(decodedStringPadded, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(outputString, output);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
}
|
||||
|
||||
@@ -865,12 +862,12 @@ public class TestPlayfair{
|
||||
public void testPracticalEncode_clean(){
|
||||
cipher = new Playfair(false, false, false);
|
||||
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
|
||||
assertEquals(inputStringClean, cipher.inputString);
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(outputStringClean, cipher.outputString);
|
||||
assertEquals(outputStringClean, output);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
}
|
||||
|
||||
@@ -878,12 +875,12 @@ public class TestPlayfair{
|
||||
public void testPracticalDecode(){
|
||||
cipher = new Playfair(true, true, true);
|
||||
|
||||
String output = cipher.decode(keyword, outputString);
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
|
||||
assertEquals(outputString, cipher.inputString);
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(inputStringPadded, cipher.outputString);
|
||||
assertEquals(inputStringPadded, output);
|
||||
assertEquals(decodedStringPadded, cipher.outputString);
|
||||
assertEquals(decodedStringPadded, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
}
|
||||
|
||||
@@ -891,12 +888,12 @@ public class TestPlayfair{
|
||||
public void testPracticalDecode_clean(){
|
||||
cipher = new Playfair(false, false, false);
|
||||
|
||||
String output = cipher.decode(keyword, outputString);
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
|
||||
assertEquals(outputStringClean, cipher.inputString);
|
||||
assertEquals(encodedStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(inputStringClean, cipher.outputString);
|
||||
assertEquals(inputStringClean, output);
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/TestPolybiusSquare.java
|
||||
//Mattrixwv
|
||||
// Created: 01-04-22
|
||||
//Modified: 04-29-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -14,13 +14,15 @@ import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
@@ -29,15 +31,18 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.PolybiusSquare.CharLocation;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestPolybiusSquare{
|
||||
@InjectMocks
|
||||
private PolybiusSquare cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Fields
|
||||
private String inputString = "Message to^encode";
|
||||
private String inputStringClean = "M E S S A G E T O E N C O D E";
|
||||
private String outputString = "41124545233212 5115^124225152212";
|
||||
private String outputStringClean = "41 12 45 45 23 32 12 51 15 12 42 25 15 22 12";
|
||||
private String keyword = "keyword";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String decodedStringClean = "M E S S A G E T O E N C O D E";
|
||||
private String encodedString = "41124545233212 5115^124225152212";
|
||||
private String encodedStringClean = "41 12 45 45 23 32 12 51 15 12 42 25 15 22 12";
|
||||
private String keyword = "ke yw*ord";
|
||||
private String keywordClean = "KEYWORDABCFGHILMNPQSTUVXZ";
|
||||
private char[][] grid = new char[][]{
|
||||
{'K', 'E', 'Y', 'W', 'O'},
|
||||
@@ -49,14 +54,6 @@ public class TestPolybiusSquare{
|
||||
private String gridString = "[K E Y W O]\n[R D A B C]\n[F G H I L]\n[M N P Q S]\n[T U V X Z]";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
cipher = new PolybiusSquare();
|
||||
logger = mock(Logger.class);
|
||||
PolybiusSquare.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
cipher = new PolybiusSquare();
|
||||
@@ -219,16 +216,16 @@ public class TestPolybiusSquare{
|
||||
cipher.replaced = 'J';
|
||||
cipher.replacer = 'I';
|
||||
|
||||
cipher.setInputStringEncode(inputString);
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
|
||||
assertEquals(inputString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", inputString);
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Checking for digits");
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -238,16 +235,16 @@ public class TestPolybiusSquare{
|
||||
cipher.replaced = 'J';
|
||||
cipher.replacer = 'I';
|
||||
|
||||
cipher.setInputStringEncode(inputString);
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
|
||||
assertEquals(inputString.toUpperCase().replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", inputString);
|
||||
assertEquals(decodedString.toUpperCase().replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Checking for digits");
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputString.toUpperCase().replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase().replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -257,16 +254,16 @@ public class TestPolybiusSquare{
|
||||
cipher.replaced = 'J';
|
||||
cipher.replacer = 'I';
|
||||
|
||||
cipher.setInputStringEncode(inputString);
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
|
||||
assertEquals(inputString.toUpperCase().replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", inputString);
|
||||
assertEquals(decodedString.toUpperCase().replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Checking for digits");
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputString.toUpperCase().replaceAll("[^a-zA-Z\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedString.toUpperCase().replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -276,16 +273,16 @@ public class TestPolybiusSquare{
|
||||
cipher.replaced = 'J';
|
||||
cipher.replacer = 'I';
|
||||
|
||||
cipher.setInputStringEncode(inputString);
|
||||
cipher.setInputStringEncode(decodedString);
|
||||
|
||||
assertEquals(inputStringClean, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", inputString);
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for encoding '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Checking for digits");
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Replacing {} with {}", cipher.replaced, cipher.replacer);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", inputStringClean);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", decodedStringClean);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -377,14 +374,14 @@ public class TestPolybiusSquare{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputStringDecode(outputString);
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
|
||||
assertEquals(outputString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", outputString);
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Checking for letters");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", outputString);
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -392,14 +389,14 @@ public class TestPolybiusSquare{
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
cipher.setInputStringDecode(outputString);
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
|
||||
assertEquals(outputString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", outputString);
|
||||
assertEquals(encodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Checking for letters");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", outputString.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -407,14 +404,14 @@ public class TestPolybiusSquare{
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
cipher.setInputStringDecode(outputString);
|
||||
cipher.setInputStringDecode(encodedString);
|
||||
|
||||
assertEquals(outputString.replaceAll("[^0-9\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", outputString);
|
||||
assertEquals(encodedString.replaceAll("[^0-9\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString);
|
||||
verify(logger, times(1)).debug("Checking for letters");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", outputString.replaceAll("[^0-9\\s]", ""));
|
||||
verify(logger, times(1)).debug("Cleaned input string '{}'", encodedString.replaceAll("[^0-9\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -423,11 +420,11 @@ public class TestPolybiusSquare{
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringDecode(outputString + "a");
|
||||
cipher.setInputStringDecode(encodedString + "a");
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", outputString + "a");
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString + "a");
|
||||
verify(logger, times(1)).debug("Checking for letters");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
@@ -440,11 +437,11 @@ public class TestPolybiusSquare{
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputStringDecode(outputString + "0");
|
||||
cipher.setInputStringDecode(encodedString + "0");
|
||||
});
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", outputString + "0");
|
||||
verify(logger, times(1)).debug("Setting input string for decoding '{}'", encodedString + "0");
|
||||
verify(logger, times(1)).debug("Checking for letters");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
@@ -504,24 +501,24 @@ public class TestPolybiusSquare{
|
||||
|
||||
@Test
|
||||
public void testGetPreparedInputStringEncode(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.inputString = decodedString;
|
||||
|
||||
String output = cipher.getPreparedInputStringEncode();
|
||||
|
||||
assertEquals(inputStringClean.replaceAll("\\s", ""), output);
|
||||
assertEquals(decodedStringClean.replaceAll("\\s", ""), output);
|
||||
verify(logger, times(1)).debug("Preparing input string for encoding");
|
||||
verify(logger, times(1)).debug("Prepared string '{}'", inputStringClean.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Prepared string '{}'", decodedStringClean.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreparedInputStringDecode(){
|
||||
cipher.inputString = outputString;
|
||||
cipher.inputString = encodedString;
|
||||
|
||||
String output = cipher.getPreparedInputStringDecode();
|
||||
|
||||
assertEquals(outputStringClean.replaceAll("\\s", ""), output);
|
||||
assertEquals(encodedStringClean.replaceAll("\\s", ""), output);
|
||||
verify(logger, times(1)).debug("Preparing input string for decoding");
|
||||
verify(logger, times(1)).debug("Prepared string '{}'", outputStringClean.replaceAll("\\s", ""));
|
||||
verify(logger, times(1)).debug("Prepared string '{}'", encodedStringClean.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -602,41 +599,41 @@ public class TestPolybiusSquare{
|
||||
|
||||
@Test
|
||||
public void testAddCharactersToCleanStringEncode(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.inputString = decodedString;
|
||||
|
||||
cipher.addCharactersToCleanStringEncode(outputStringClean.replaceAll("\\D", ""));
|
||||
cipher.addCharactersToCleanStringEncode(encodedStringClean.replaceAll("\\D", ""));
|
||||
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string for encoding");
|
||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(15)).debug("Adding encoded characters");
|
||||
verify(logger, times(2)).debug("Adding symbols");
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", outputString);
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", encodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddCharactersToCleanStringDecode(){
|
||||
cipher.inputString = outputString;
|
||||
cipher.inputString = encodedString;
|
||||
|
||||
cipher.addCharactersToCleanStringDecode(inputStringClean.replaceAll("\\s", ""));
|
||||
cipher.addCharactersToCleanStringDecode(decodedStringClean.replaceAll("\\s", ""));
|
||||
|
||||
assertEquals(inputString.toUpperCase(), cipher.outputString);
|
||||
assertEquals(decodedString.toUpperCase(), cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string for decoding");
|
||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(15)).debug("Adding decoded characters");
|
||||
verify(logger, times(2)).debug("Adding symbols");
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", inputString.toUpperCase());
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", decodedString.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = inputString.toUpperCase();
|
||||
cipher.inputString = decodedString.toUpperCase();
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(15)).debug(eq("Current working character {}"), anyChar());
|
||||
verify(logger, times(15)).debug(eq("Location {}, {}"), anyInt(), anyInt());
|
||||
@@ -644,13 +641,13 @@ public class TestPolybiusSquare{
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.inputString = outputString;
|
||||
cipher.inputString = encodedString;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.grid = grid;
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(inputString.toUpperCase(), cipher.outputString);
|
||||
assertEquals(decodedString.toUpperCase(), cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(15)).debug(eq("Digits to decode {} {}"), anyChar(), anyChar());
|
||||
verify(logger, times(15)).debug(eq("Decoded letter {}"), anyChar());
|
||||
@@ -658,14 +655,14 @@ public class TestPolybiusSquare{
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.keyword = keywordClean;
|
||||
cipher.outputString = outputString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.grid = grid;
|
||||
|
||||
assertEquals(inputString, cipher.getInputString());
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(keywordClean, cipher.getKeyword());
|
||||
assertEquals(outputString, cipher.getOutputString());
|
||||
assertEquals(encodedString, cipher.getOutputString());
|
||||
assertEquals("[K E Y W O]\n[R D A B C]\n[F G H I L]\n[M N P Q S]\n[T U V X Z]", cipher.getGrid());
|
||||
assertEquals('J', cipher.getReplaced());
|
||||
assertEquals('I', cipher.getReplacer());
|
||||
@@ -673,9 +670,9 @@ public class TestPolybiusSquare{
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = inputString;
|
||||
cipher.inputString = decodedString;
|
||||
cipher.keyword = keyword;
|
||||
cipher.outputString = outputString;
|
||||
cipher.outputString = encodedString;
|
||||
cipher.grid = grid;
|
||||
|
||||
cipher.reset();
|
||||
@@ -692,12 +689,12 @@ public class TestPolybiusSquare{
|
||||
public void testPracticalEncode(){
|
||||
cipher = new PolybiusSquare(true, true);
|
||||
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
|
||||
assertEquals(inputString.toUpperCase(), cipher.inputString);
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(outputString, cipher.outputString);
|
||||
assertEquals(outputString, output);
|
||||
assertEquals(encodedString, cipher.outputString);
|
||||
assertEquals(encodedString, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
}
|
||||
|
||||
@@ -705,12 +702,12 @@ public class TestPolybiusSquare{
|
||||
public void testPracticalEncode_clean(){
|
||||
cipher = new PolybiusSquare(false, false);
|
||||
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
String output = cipher.encode(keyword, decodedString);
|
||||
|
||||
assertEquals(inputStringClean, cipher.inputString);
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(outputStringClean, cipher.outputString);
|
||||
assertEquals(outputStringClean, output);
|
||||
assertEquals(encodedStringClean, cipher.outputString);
|
||||
assertEquals(encodedStringClean, output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
}
|
||||
|
||||
@@ -718,12 +715,12 @@ public class TestPolybiusSquare{
|
||||
public void testPracticalDecode(){
|
||||
cipher = new PolybiusSquare(true, true);
|
||||
|
||||
String output = cipher.decode(keyword, outputString);
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
|
||||
assertEquals(outputString, cipher.inputString);
|
||||
assertEquals(encodedString, cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(inputString.toUpperCase(), cipher.outputString);
|
||||
assertEquals(inputString.toUpperCase(), output);
|
||||
assertEquals(decodedString.toUpperCase(), cipher.outputString);
|
||||
assertEquals(decodedString.toUpperCase(), output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
}
|
||||
|
||||
@@ -731,12 +728,12 @@ public class TestPolybiusSquare{
|
||||
public void testPracticalDecode_clean(){
|
||||
cipher = new PolybiusSquare(false, false);
|
||||
|
||||
String output = cipher.decode(keyword, outputString);
|
||||
String output = cipher.decode(keyword, encodedString);
|
||||
|
||||
assertEquals(outputString.replaceAll("\\s", "").replaceAll("[^0-9]", ""), cipher.inputString);
|
||||
assertEquals(encodedString.replaceAll("\\s", "").replaceAll("[^0-9]", ""), cipher.inputString);
|
||||
assertEquals(keywordClean, cipher.keyword);
|
||||
assertEquals(inputStringClean.replaceAll("\\s", ""), cipher.outputString);
|
||||
assertEquals(inputStringClean.replaceAll("\\s", ""), output);
|
||||
assertEquals(decodedStringClean.replaceAll("\\s", ""), cipher.outputString);
|
||||
assertEquals(decodedStringClean.replaceAll("\\s", ""), output);
|
||||
assertArrayEquals(grid, cipher.grid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,537 +1,455 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestRailFence.java
|
||||
//Mattrixwv
|
||||
// Created: 03-21-22
|
||||
//Modified: 07-09-22
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyChar;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidBaseException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestRailFence{
|
||||
@InjectMocks
|
||||
private RailFence cipher;
|
||||
@Mock
|
||||
private Logger logger;
|
||||
//Fields
|
||||
private String decodedString = "Message to^encode";
|
||||
private String decodedStringClean = "MESSAGETOENCODE";
|
||||
private String encodedString3 = "Maooesg te^cdsene";
|
||||
private String encodedString3Clean = "MAOOESGTECDSENE";
|
||||
private String encodedString5 = "Moetese ne^sgcdao";
|
||||
private String encodedString5Clean = "MOETESENESGCDAO";
|
||||
private StringBuilder[] fence3 = new StringBuilder[]{
|
||||
new StringBuilder("Maoo"),
|
||||
new StringBuilder("esgtecd"),
|
||||
new StringBuilder("sene")
|
||||
};
|
||||
private StringBuilder[] fence5 = new StringBuilder[]{
|
||||
new StringBuilder("Mo"),
|
||||
new StringBuilder("ete"),
|
||||
new StringBuilder("sene"),
|
||||
new StringBuilder("sgcd"),
|
||||
new StringBuilder("ao")
|
||||
};
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncode() throws InvalidBaseException, InvalidInputException{
|
||||
RailFence cipher = new RailFence(true, true, true);
|
||||
public void testConstructor_default(){
|
||||
cipher = new RailFence();
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
int numRails = 3;
|
||||
String correctOutput = "maooesgtecdsene";
|
||||
String output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length encoding
|
||||
inputString = "messagetoencode";
|
||||
numRails = 5;
|
||||
correctOutput = "moetesenesgcdao";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
numRails = 3;
|
||||
correctOutput = "maooesg te cdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
numRails = 3;
|
||||
correctOutput = "maooesg*te+cdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
numRails = 3;
|
||||
correctOutput = "Maooesg te^cdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Message to^encode";
|
||||
numRails = 5;
|
||||
correctOutput = "Moetese ne^sgcdao";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertNull(cipher.fence);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNocapitalEncode() throws InvalidBaseException, InvalidInputException{
|
||||
RailFence cipher = new RailFence(false, true, true);
|
||||
public void testConstructor_noCapitals(){
|
||||
cipher = new RailFence(false, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
int numRails = 3;
|
||||
String correctOutput = "MAOOESGTECDSENE";
|
||||
String output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length encoding
|
||||
inputString = "messagetoencode";
|
||||
numRails = 5;
|
||||
correctOutput = "MOETESENESGCDAO";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESG TE CDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESG*TE+CDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESG TE^CDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Message to^encode";
|
||||
numRails = 5;
|
||||
correctOutput = "MOETESE NE^SGCDAO";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
assertFalse(cipher.preserveCapitals);
|
||||
assertTrue(cipher.preserveWhitespace);
|
||||
assertTrue(cipher.preserveSymbols);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertNull(cipher.fence);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidBaseException, InvalidInputException{
|
||||
RailFence cipher = new RailFence(true, false, true);
|
||||
public void testConstructor_noWhitespace(){
|
||||
cipher = new RailFence(true, false, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
int numRails = 3;
|
||||
String correctOutput = "maooesgtecdsene";
|
||||
String output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length encoding
|
||||
inputString = "messagetoencode";
|
||||
numRails = 5;
|
||||
correctOutput = "moetesenesgcdao";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
numRails = 3;
|
||||
correctOutput = "maooesgtecdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
numRails = 3;
|
||||
correctOutput = "maooesg*te+cdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
numRails = 3;
|
||||
correctOutput = "Maooesgte^cdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Message to^encode";
|
||||
numRails = 5;
|
||||
correctOutput = "Moetesene^sgcdao";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
assertTrue(cipher.preserveCapitals);
|
||||
assertFalse(cipher.preserveWhitespace);
|
||||
assertTrue(cipher.preserveSymbols);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertNull(cipher.fence);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidBaseException, InvalidInputException{
|
||||
RailFence cipher = new RailFence(true, true, false);
|
||||
public void testConstructor_noSymbols(){
|
||||
cipher = new RailFence(true, true, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
int numRails = 3;
|
||||
String correctOutput = "maooesgtecdsene";
|
||||
String output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length encoding
|
||||
inputString = "messagetoencode";
|
||||
numRails = 5;
|
||||
correctOutput = "moetesenesgcdao";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
numRails = 3;
|
||||
correctOutput = "maooesg te cdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
numRails = 3;
|
||||
correctOutput = "maooesgtecdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
numRails = 3;
|
||||
correctOutput = "Maooesg tecdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Message to^encode";
|
||||
numRails = 5;
|
||||
correctOutput = "Moetese nesgcdao";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
assertTrue(cipher.preserveCapitals);
|
||||
assertTrue(cipher.preserveWhitespace);
|
||||
assertFalse(cipher.preserveSymbols);
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertNull(cipher.fence);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidBaseException, InvalidInputException{
|
||||
RailFence cipher = new RailFence(false, false, false);
|
||||
public void testSetInputString(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "messagetoencode";
|
||||
int numRails = 3;
|
||||
String correctOutput = "MAOOESGTECDSENE";
|
||||
String output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
cipher.setInputString(decodedString);
|
||||
|
||||
//Test rail length encoding
|
||||
inputString = "messagetoencode";
|
||||
numRails = 5;
|
||||
correctOutput = "MOETESENESGCDAO";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Message to^encode";
|
||||
numRails = 5;
|
||||
correctOutput = "MOETESENESGCDAO";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecode() throws InvalidBaseException, InvalidInputException{
|
||||
RailFence cipher = new RailFence(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "maooesgtecdsene";
|
||||
int numRails = 3;
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MAOOESGTECDSENE";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length decoding
|
||||
inputString = "moetesenesgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "maooesg te cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "maooesg*te+cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Maooesg te^cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Moetese ne^sgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", decodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws InvalidBaseException, InvalidInputException{
|
||||
RailFence cipher = new RailFence(false, true, true);
|
||||
public void testSetInputString_noCapitals(){
|
||||
cipher.preserveCapitals = false;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "maooesgtecdsene";
|
||||
int numRails = 3;
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MAOOESGTECDSENE";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
cipher.setInputString(decodedString);
|
||||
|
||||
//Test rail length decoding
|
||||
inputString = "moetesenesgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "maooesg te cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "maooesg*te+cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGE*TO+ENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Maooesg te^cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Moetese ne^sgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
assertEquals(decodedString.toUpperCase(), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, times(1)).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", decodedString.toUpperCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws InvalidBaseException, InvalidInputException{
|
||||
RailFence cipher = new RailFence(true, false, true);
|
||||
public void testSetInputString_noWhitespace(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = false;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "maooesgtecdsene";
|
||||
int numRails = 3;
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MAOOESGTECDSENE";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
cipher.setInputString(decodedString);
|
||||
|
||||
//Test rail length decoding
|
||||
inputString = "moetesenesgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "maooesg te cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "maooesg*te+cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Maooesg te^cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Moetese ne^sgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, times(1)).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", decodedString.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws InvalidBaseException, InvalidInputException{
|
||||
RailFence cipher = new RailFence(true, true, false);
|
||||
public void testSetInputString_noSymbols(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = false;
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "maooesgtecdsene";
|
||||
int numRails = 3;
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MAOOESGTECDSENE";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
cipher.setInputString(decodedString);
|
||||
|
||||
//Test rail length decoding
|
||||
inputString = "moetesenesgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "maooesg te cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "maooesg*te+cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Maooesg te^cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Moetese ne^sgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, times(1)).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", decodedString.replaceAll("[^a-zA-Z\\s]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidBaseException, InvalidInputException{
|
||||
RailFence cipher = new RailFence(false, false, false);
|
||||
public void testSetInputString_blank(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "maooesgtecdsene";
|
||||
int numRails = 3;
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MAOOESGTECDSENE";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString("");
|
||||
});
|
||||
|
||||
//Test rail length decoding
|
||||
inputString = "moetesenesgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, times(1)).debug("Original input string '{}'", "");
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, times(1)).debug("Clean input string '{}'", "");
|
||||
}
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "maooesg te cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
@Test
|
||||
public void testSetInputString_null(){
|
||||
cipher.preserveCapitals = true;
|
||||
cipher.preserveWhitespace = true;
|
||||
cipher.preserveSymbols = true;
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "maooesg*te+cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
assertThrows(InvalidInputException.class, () -> {
|
||||
cipher.setInputString(null);
|
||||
});
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Maooesg te^cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Moetese ne^sgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals(correctOutput, output);
|
||||
assertEquals("", cipher.inputString);
|
||||
verify(logger, never()).debug(eq("Original input string '{}'"), anyString());
|
||||
verify(logger, never()).debug("Removing case");
|
||||
verify(logger, never()).debug("Removing whitespace");
|
||||
verify(logger, never()).debug("Removing symbols");
|
||||
verify(logger, never()).debug(eq("Clean input string '{}'"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetNumRails(){
|
||||
cipher.setNumRails(3);
|
||||
|
||||
assertEquals(3, cipher.fence.length);
|
||||
verify(logger, times(1)).debug("Creating {} rails", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetNumRails_short(){
|
||||
assertThrows(InvalidBaseException.class, () -> {
|
||||
cipher.setNumRails(1);
|
||||
});
|
||||
|
||||
assertNull(cipher.fence);
|
||||
verify(logger, never()).debug(eq("Creating {} rails"), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCleanInputString(){
|
||||
cipher.inputString = decodedString;
|
||||
|
||||
String output = cipher.getCleanInputString();
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z]", ""), output);
|
||||
verify(logger, times(1)).debug("Getting input string for encoding");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatOutput(){
|
||||
cipher.inputString = decodedString;
|
||||
|
||||
cipher.formatOutput(encodedString3Clean);
|
||||
|
||||
assertEquals(encodedString3, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Formatting output string");
|
||||
verify(logger, times(17)).debug(eq("Working character {}"), anyChar());
|
||||
verify(logger, times(1)).debug("Formatting uppercase");
|
||||
verify(logger, times(14)).debug("Formatting lowercase");
|
||||
verify(logger, times(2)).debug("Inserting symbol");
|
||||
verify(logger, times(1)).debug("Formatted output '{}'", encodedString3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDecodedStringFromFence(){
|
||||
cipher.fence = fence3;
|
||||
|
||||
String output = cipher.getDecodedStringFromFence();
|
||||
|
||||
assertEquals(decodedString.replaceAll("[^a-zA-Z]", ""), output);
|
||||
verify(logger, times(1)).debug("Getting decoded string from the fence");
|
||||
verify(logger, times(1)).debug(eq("Fence output '{}'"), any(StringBuilder.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.fence = new StringBuilder[]{
|
||||
new StringBuilder(),
|
||||
new StringBuilder(),
|
||||
new StringBuilder()
|
||||
};
|
||||
|
||||
cipher.encode();
|
||||
|
||||
assertEquals(encodedString3, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Encoding");
|
||||
verify(logger, times(15)).debug(eq("Working character '{}'"), anyChar());
|
||||
verify(logger, times(9)).debug("Moving up");
|
||||
verify(logger, times(6)).debug("Moving down");
|
||||
verify(logger, times(4)).debug("Swapping to down");
|
||||
verify(logger, times(3)).debug("Swapping to up");
|
||||
verify(logger, times(1)).debug("Appending rows from the fence");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecode(){
|
||||
cipher.inputString = encodedString3;
|
||||
cipher.fence = new StringBuilder[]{
|
||||
new StringBuilder(),
|
||||
new StringBuilder(),
|
||||
new StringBuilder()
|
||||
};
|
||||
|
||||
cipher.decode();
|
||||
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
verify(logger, times(1)).debug("Decoding");
|
||||
verify(logger, times(1)).debug("Number of characters in the top rail {}", 4);
|
||||
verify(logger, times(1)).debug("Number of characters in the middle rails {}", 8);
|
||||
verify(logger, times(1)).debug("Number of characters in the bottom rail {}", 4);
|
||||
verify(logger, times(1)).debug("Adding characters to the rails");
|
||||
verify(logger, times(1)).debug("Appending the bottom rail");
|
||||
verify(logger, times(1)).debug("Fence output '{}'", decodedString.replaceAll("[^a-zA-Z]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetters(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString3;
|
||||
cipher.fence = fence3;
|
||||
|
||||
assertEquals(decodedString, cipher.getInputString());
|
||||
assertEquals(encodedString3, cipher.getOutputString());
|
||||
assertEquals(fence3.length, cipher.getNumRails());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset(){
|
||||
cipher.inputString = decodedString;
|
||||
cipher.outputString = encodedString3;
|
||||
cipher.fence = fence3;
|
||||
|
||||
cipher.reset();
|
||||
|
||||
assertEquals("", cipher.inputString);
|
||||
assertEquals("", cipher.outputString);
|
||||
assertNull(cipher.fence);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_3(){
|
||||
cipher = new RailFence(true, true, true);
|
||||
|
||||
String output = cipher.encode(3, decodedString);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(fence3.length, cipher.fence.length);
|
||||
assertEquals(fence3[0].toString(), cipher.fence[0].toString());
|
||||
assertEquals(fence3[1].toString(), cipher.fence[1].toString());
|
||||
assertEquals(fence3[2].toString(), cipher.fence[2].toString());
|
||||
assertEquals(encodedString3, cipher.outputString);
|
||||
assertEquals(encodedString3, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_3Clean(){
|
||||
cipher = new RailFence(false, false, false);
|
||||
|
||||
String output = cipher.encode(3, decodedString);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(fence3.length, cipher.fence.length);
|
||||
assertEquals(fence3[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||
assertEquals(fence3[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||
assertEquals(fence3[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||
assertEquals(encodedString3Clean, cipher.outputString);
|
||||
assertEquals(encodedString3Clean, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_5(){
|
||||
cipher = new RailFence(true, true, true);
|
||||
|
||||
String output = cipher.encode(5, decodedString);
|
||||
|
||||
assertEquals(decodedString, cipher.inputString);
|
||||
assertEquals(fence5.length, cipher.fence.length);
|
||||
assertEquals(fence5[0].toString(), cipher.fence[0].toString());
|
||||
assertEquals(fence5[1].toString(), cipher.fence[1].toString());
|
||||
assertEquals(fence5[2].toString(), cipher.fence[2].toString());
|
||||
assertEquals(fence5[3].toString(), cipher.fence[3].toString());
|
||||
assertEquals(fence5[4].toString(), cipher.fence[4].toString());
|
||||
assertEquals(encodedString5, cipher.outputString);
|
||||
assertEquals(encodedString5, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalEncoding_5Clean(){
|
||||
cipher = new RailFence(false, false, false);
|
||||
|
||||
String output = cipher.encode(5, decodedString);
|
||||
|
||||
assertEquals(decodedStringClean, cipher.inputString);
|
||||
assertEquals(fence5.length, cipher.fence.length);
|
||||
assertEquals(fence5[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||
assertEquals(fence5[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||
assertEquals(fence5[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||
assertEquals(fence5[3].toString().toUpperCase(), cipher.fence[3].toString());
|
||||
assertEquals(fence5[4].toString().toUpperCase(), cipher.fence[4].toString());
|
||||
assertEquals(encodedString5Clean, cipher.outputString);
|
||||
assertEquals(encodedString5Clean, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_3(){
|
||||
cipher = new RailFence(true, true, true);
|
||||
|
||||
String output = cipher.decode(3, encodedString3);
|
||||
|
||||
assertEquals(encodedString3, cipher.inputString);
|
||||
assertEquals(fence3.length, cipher.fence.length);
|
||||
assertEquals(fence3[0].toString(), cipher.fence[0].toString());
|
||||
assertEquals(fence3[1].toString(), cipher.fence[1].toString());
|
||||
assertEquals(fence3[2].toString(), cipher.fence[2].toString());
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_3Clean(){
|
||||
cipher = new RailFence(false, false, false);
|
||||
|
||||
String output = cipher.decode(3, encodedString3);
|
||||
|
||||
assertEquals(encodedString3Clean, cipher.inputString);
|
||||
assertEquals(fence3.length, cipher.fence.length);
|
||||
assertEquals(fence3[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||
assertEquals(fence3[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||
assertEquals(fence3[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_5(){
|
||||
cipher = new RailFence(true, true, true);
|
||||
|
||||
String output = cipher.decode(5, encodedString5);
|
||||
|
||||
assertEquals(encodedString5, cipher.inputString);
|
||||
assertEquals(fence5.length, cipher.fence.length);
|
||||
assertEquals(fence5[0].toString(), cipher.fence[0].toString());
|
||||
assertEquals(fence5[1].toString(), cipher.fence[1].toString());
|
||||
assertEquals(fence5[2].toString(), cipher.fence[2].toString());
|
||||
assertEquals(fence5[3].toString(), cipher.fence[3].toString());
|
||||
assertEquals(fence5[4].toString(), cipher.fence[4].toString());
|
||||
assertEquals(decodedString, cipher.outputString);
|
||||
assertEquals(decodedString, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPracticalDecoding_5Clean(){
|
||||
cipher = new RailFence(false, false, false);
|
||||
|
||||
String output = cipher.decode(5, encodedString5);
|
||||
|
||||
assertEquals(encodedString5Clean, cipher.inputString);
|
||||
assertEquals(fence5.length, cipher.fence.length);
|
||||
assertEquals(fence5[0].toString().toUpperCase(), cipher.fence[0].toString());
|
||||
assertEquals(fence5[1].toString().toUpperCase(), cipher.fence[1].toString());
|
||||
assertEquals(fence5[2].toString().toUpperCase(), cipher.fence[2].toString());
|
||||
assertEquals(fence5[3].toString().toUpperCase(), cipher.fence[3].toString());
|
||||
assertEquals(fence5[4].toString().toUpperCase(), cipher.fence[4].toString());
|
||||
assertEquals(decodedStringClean, cipher.outputString);
|
||||
assertEquals(decodedStringClean, output);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user