Fix sonarqube issues

This commit is contained in:
2026-01-26 22:23:05 -05:00
parent 1943f19b4e
commit 8e41b0a2ad
34 changed files with 1885 additions and 2081 deletions

View File

@@ -1,7 +1,3 @@
//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/combination/TestADFGVX.java
//Mattrixwv
// Created: 01-26-22
//Modified: 04-19-24
package com.mattrixwv.cipherstream.combination;
@@ -29,12 +25,12 @@ public class ADFGVXTest{
@Mock
private Logger logger;
//Variables
private static final String decodedString = "Message to^encode";
private static final String decodedStringClean = "MESSAGETOENCODE";
private static final String encodedString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
private static final String encodedStringClean = "AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA";
private static final String keyword = "keyword";
private static final String squareKeyword = "SquareKeyword";
private static final String DECODED_STRING = "Message to^encode";
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
private static final String ENCODED_STRING = "AXgvdavfxgagfa afag^aaxdxfgdagda";
private static final String ENCODED_STRING_CLEAN = "AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA";
private static final String KEYWORD = "keyword";
private static final String SQUARE_KEYWORD = "SquareKeyword";
@Test
@@ -99,10 +95,10 @@ public class ADFGVXTest{
@Test
public void testSetSquareKeyword(){
cipher.setSquareKeyword(squareKeyword);
cipher.setSquareKeyword(SQUARE_KEYWORD);
assertEquals(squareKeyword, cipher.squareKeyword);
verify(logger, times(1)).debug("squareKeyword '{}'", squareKeyword);
assertEquals(SQUARE_KEYWORD, cipher.squareKeyword);
verify(logger, times(1)).debug("squareKeyword '{}'", SQUARE_KEYWORD);
}
@Test
@@ -117,10 +113,10 @@ public class ADFGVXTest{
@Test
public void testSetKeyword(){
cipher.setKeyword(keyword);
cipher.setKeyword(KEYWORD);
assertEquals(keyword, cipher.keyword);
verify(logger, times(1)).debug("keyword '{}'", keyword);
assertEquals(KEYWORD, cipher.keyword);
verify(logger, times(1)).debug("keyword '{}'", KEYWORD);
}
@Test
@@ -139,14 +135,14 @@ public class ADFGVXTest{
cipher.preserveWhitespace = true;
cipher.preserveSymbols = true;
cipher.setInputString(decodedString);
cipher.setInputString(DECODED_STRING);
assertEquals(decodedString, cipher.inputString);
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
assertEquals(DECODED_STRING, cipher.inputString);
verify(logger, times(1)).debug("Original input string '{}'", DECODED_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 '{}'", decodedString);
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING);
}
@Test
@@ -155,14 +151,14 @@ public class ADFGVXTest{
cipher.preserveWhitespace = true;
cipher.preserveSymbols = true;
cipher.setInputString(decodedString);
cipher.setInputString(DECODED_STRING);
assertEquals(decodedString.toUpperCase(), cipher.inputString);
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
assertEquals(DECODED_STRING.toUpperCase(), cipher.inputString);
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
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());
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.toUpperCase());
}
@Test
@@ -171,14 +167,14 @@ public class ADFGVXTest{
cipher.preserveWhitespace = false;
cipher.preserveSymbols = true;
cipher.setInputString(decodedString);
cipher.setInputString(DECODED_STRING);
assertEquals(decodedString.replaceAll("\\s", ""), cipher.inputString);
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
assertEquals(DECODED_STRING.replaceAll("\\s", ""), cipher.inputString);
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
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", ""));
verify(logger, times(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("\\s", ""));
}
@Test
@@ -187,14 +183,14 @@ public class ADFGVXTest{
cipher.preserveWhitespace = true;
cipher.preserveSymbols = false;
cipher.setInputString(decodedString);
cipher.setInputString(DECODED_STRING);
assertEquals(decodedString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
assertEquals(DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
verify(logger, never()).debug("Removing capitals");
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("Cleaned input string '{}'", DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""));
}
@Test
@@ -235,45 +231,45 @@ public class ADFGVXTest{
@Test
public void testFormateOutputStringEncode(){
cipher.inputString = decodedString;
cipher.outputString = encodedStringClean;
cipher.inputString = DECODED_STRING;
cipher.outputString = ENCODED_STRING_CLEAN;
cipher.formatOutputStringEncode();
assertEquals(encodedString, cipher.outputString);
assertEquals(ENCODED_STRING, cipher.outputString);
verify(logger, times(1)).debug("Formatting output string to match input string");
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
verify(logger, times(1)).debug("Converting output to uppercase");
verify(logger, times(14)).debug("Converting output to lowercase");
verify(logger, times(2)).debug("Appending symbol to output");
verify(logger, times(1)).debug("Saving output string '{}'", encodedString);
verify(logger, times(1)).debug("Saving output string '{}'", ENCODED_STRING);
}
@Test
public void testFormatOutputStringDecode(){
cipher.outputString = decodedStringClean;
cipher.inputString = encodedString;
cipher.outputString = DECODED_STRING_CLEAN;
cipher.inputString = ENCODED_STRING;
cipher.formatOutputStringDecode();
assertEquals(decodedString, cipher.outputString);
assertEquals(DECODED_STRING, cipher.outputString);
verify(logger, times(1)).debug("Formatting output string to match input string");
verify(logger, times(17)).debug(eq("Input character {}"), anyChar());
verify(logger, times(1)).debug("Converting output to uppercase");
verify(logger, times(14)).debug("Converting output to lowercase");
verify(logger, times(2)).debug("Appending symbol to output");
verify(logger, times(1)).debug("Saving output string '{}'", decodedString);
verify(logger, times(1)).debug("Saving output string '{}'", DECODED_STRING);
}
@Test
public void testEncode(){
cipher.inputString = decodedString;
cipher.keyword = keyword;
cipher.squareKeyword = squareKeyword;
cipher.inputString = DECODED_STRING;
cipher.keyword = KEYWORD;
cipher.squareKeyword = SQUARE_KEYWORD;
cipher.encode();
assertEquals(encodedString, cipher.outputString);
assertEquals(ENCODED_STRING, cipher.outputString);
verify(logger, times(1)).debug("Encoding using Polybius Square");
verify(logger, times(1)).debug("Replacing coordinates with letters");
verify(logger, times(1)).debug("Encoding using columnar");
@@ -281,13 +277,13 @@ public class ADFGVXTest{
@Test
public void testDecode(){
cipher.inputString = encodedString;
cipher.keyword = keyword;
cipher.squareKeyword = squareKeyword;
cipher.inputString = ENCODED_STRING;
cipher.keyword = KEYWORD;
cipher.squareKeyword = SQUARE_KEYWORD;
cipher.decode();
assertEquals(decodedString, cipher.outputString);
assertEquals(DECODED_STRING, cipher.outputString);
verify(logger, times(1)).debug("Decoding using columnar");
verify(logger, times(1)).debug("Replacing letters with coordinates");
verify(logger, times(1)).debug("Decoding using Polybius Square");
@@ -295,25 +291,25 @@ public class ADFGVXTest{
@Test
public void testGetters(){
cipher.inputString = decodedString;
cipher.outputString = encodedString;
cipher.squareKeyword = squareKeyword;
cipher.keyword = keyword;
cipher.inputString = DECODED_STRING;
cipher.outputString = ENCODED_STRING;
cipher.squareKeyword = SQUARE_KEYWORD;
cipher.keyword = KEYWORD;
assertEquals(decodedString, cipher.getInputString());
assertEquals(encodedString, cipher.getOutputString());
assertEquals(squareKeyword, cipher.getSquareKeyword());
assertEquals(keyword, cipher.getKeyword());
assertEquals(DECODED_STRING, cipher.getInputString());
assertEquals(ENCODED_STRING, cipher.getOutputString());
assertEquals(SQUARE_KEYWORD, cipher.getSquareKeyword());
assertEquals(KEYWORD, cipher.getKeyword());
}
@Test
public void testReset(){
LargePolybiusSquare ps = cipher.largePolybiusSquare;
Columnar columnar = cipher.columnar;
cipher.inputString = decodedString;
cipher.outputString = encodedString;
cipher.squareKeyword = squareKeyword;
cipher.keyword = keyword;
cipher.inputString = DECODED_STRING;
cipher.outputString = ENCODED_STRING;
cipher.squareKeyword = SQUARE_KEYWORD;
cipher.keyword = KEYWORD;
cipher.reset();
@@ -330,47 +326,47 @@ public class ADFGVXTest{
public void testPracticalEncoding(){
cipher = new ADFGVX(true, true, true);
String output = cipher.encode(squareKeyword, keyword, decodedString);
String output = cipher.encode(SQUARE_KEYWORD, KEYWORD, DECODED_STRING);
assertEquals(decodedString, cipher.inputString);
assertEquals(keyword, cipher.keyword);
assertEquals(encodedString, cipher.outputString);
assertEquals(encodedString, output);
assertEquals(DECODED_STRING, cipher.inputString);
assertEquals(KEYWORD, cipher.keyword);
assertEquals(ENCODED_STRING, cipher.outputString);
assertEquals(ENCODED_STRING, output);
}
@Test
public void testPracticalEncoding_clean(){
cipher = new ADFGVX(false, false, false);
String output = cipher.encode(squareKeyword, keyword, decodedString);
String output = cipher.encode(SQUARE_KEYWORD, KEYWORD, DECODED_STRING);
assertEquals(decodedStringClean, cipher.inputString);
assertEquals(keyword, cipher.keyword);
assertEquals(encodedStringClean, cipher.outputString);
assertEquals(encodedStringClean, output);
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
assertEquals(KEYWORD, cipher.keyword);
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
assertEquals(ENCODED_STRING_CLEAN, output);
}
@Test
public void testPracticalDecoding(){
cipher = new ADFGVX(true, true, true);
String output = cipher.decode(squareKeyword, keyword, encodedString);
String output = cipher.decode(SQUARE_KEYWORD, KEYWORD, ENCODED_STRING);
assertEquals(encodedString, cipher.inputString);
assertEquals(keyword, cipher.keyword);
assertEquals(decodedString, cipher.outputString);
assertEquals(decodedString, output);
assertEquals(ENCODED_STRING, cipher.inputString);
assertEquals(KEYWORD, cipher.keyword);
assertEquals(DECODED_STRING, cipher.outputString);
assertEquals(DECODED_STRING, output);
}
@Test
public void testPracticalDecoding_clean(){
cipher = new ADFGVX(false, false, false);
String output = cipher.decode(squareKeyword, keyword, encodedString);
String output = cipher.decode(SQUARE_KEYWORD, KEYWORD, ENCODED_STRING);
assertEquals(encodedStringClean, cipher.inputString);
assertEquals(keyword, cipher.keyword);
assertEquals(decodedStringClean, cipher.outputString);
assertEquals(decodedStringClean, output);
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
assertEquals(KEYWORD, cipher.keyword);
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
assertEquals(DECODED_STRING_CLEAN, output);
}
}