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/CipherStreamJava/CaesarTest.java
//Matthew Ellison
// Created: 07-25-21
//Modified: 04-19-24
package com.mattrixwv.cipherstream.monosubstitution;
@@ -26,11 +22,11 @@ public class CaesarTest{
@Mock
private Logger logger;
//Variables
private static final String decodedString = "The quick brown fox jumps over - the lAzy dog";
private static final String decodedStringClean = "thequickbrownfoxjumpsoverthelazydog";
private static final String encodedString = "Qeb nrfzh yoltk clu grjmp lsbo - qeb iXwv ald";
private static final String encodedStringClean = "qebnrfzhyoltkclugrjmplsboqebixwvald";
private static final int shift = 23;
private static final String DECODED_STRING = "The quick brown fox jumps over - the lAzy dog";
private static final String DECODED_STRING_CLEAN = "thequickbrownfoxjumpsoverthelazydog";
private static final String ENCODED_STRING = "Qeb nrfzh yoltk clu grjmp lsbo - qeb iXwv ald";
private static final String ENCODED_STRING_CLEAN = "qebnrfzhyoltkclugrjmplsboqebixwvald";
private static final int SHIFT = 23;
@Test
@@ -83,29 +79,29 @@ public class CaesarTest{
@Test
public void testSetShift(){
cipher.setShift(shift);
cipher.setShift(SHIFT);
assertEquals(shift, cipher.shift);
verify(logger, times(1)).debug("Setting shift {}", shift);
verify(logger, times(1)).debug("Cleaned shift {}", shift);
assertEquals(SHIFT, cipher.shift);
verify(logger, times(1)).debug("Setting shift {}", SHIFT);
verify(logger, times(1)).debug("Cleaned shift {}", SHIFT);
}
@Test
public void testSetShift_large(){
cipher.setShift(shift + 26);
cipher.setShift(SHIFT + 26);
assertEquals(shift, cipher.shift);
verify(logger, times(1)).debug("Setting shift {}", shift + 26);
verify(logger, times(1)).debug("Cleaned shift {}", shift);
assertEquals(SHIFT, cipher.shift);
verify(logger, times(1)).debug("Setting shift {}", SHIFT + 26);
verify(logger, times(1)).debug("Cleaned shift {}", SHIFT);
}
@Test
public void testSetShift_negative(){
cipher.setShift(shift - 26);
cipher.setShift(SHIFT - 26);
assertEquals(shift - 26, cipher.shift);
verify(logger, times(1)).debug("Setting shift {}", shift - 26);
verify(logger, times(1)).debug("Cleaned shift {}", shift - 26);
assertEquals(SHIFT, cipher.shift);
verify(logger, times(1)).debug("Setting shift {}", SHIFT - 26);
verify(logger, times(1)).debug("Cleaned shift {}", SHIFT);
}
@Test
@@ -114,14 +110,14 @@ public class CaesarTest{
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 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(1)).debug("Cleaned input string '{}'", DECODED_STRING);
}
@Test
@@ -130,14 +126,14 @@ public class CaesarTest{
cipher.preserveWhitespace = true;
cipher.preserveSymbols = true;
cipher.setInputString(decodedString);
cipher.setInputString(DECODED_STRING);
assertEquals(decodedString.toLowerCase(), cipher.inputString);
verify(logger, times(1)).debug("Original input string '{}'", decodedString);
assertEquals(DECODED_STRING.toLowerCase(), cipher.inputString);
verify(logger, times(1)).debug("Original input string '{}'", DECODED_STRING);
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(1)).debug("Cleaned input string '{}'", DECODED_STRING.toLowerCase());
}
@Test
@@ -146,14 +142,14 @@ public class CaesarTest{
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 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(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("\\s", ""));
}
@Test
@@ -162,14 +158,14 @@ public class CaesarTest{
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 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(1)).debug("Cleaned input string '{}'", DECODED_STRING.replaceAll("[^a-zA-Z\\s]", ""));
}
@Test
@@ -210,12 +206,12 @@ public class CaesarTest{
@Test
public void testEncode(){
cipher.inputString = decodedString;
cipher.shift = shift;
cipher.inputString = DECODED_STRING;
cipher.shift = SHIFT;
cipher.encode();
assertEquals(encodedString, cipher.outputString);
assertEquals(ENCODED_STRING, cipher.outputString);
verify(logger, times(1)).debug("Encoding");
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
verify(logger, times(2)).debug("Encoding uppercase");
@@ -225,17 +221,17 @@ public class CaesarTest{
verify(logger, never()).debug("Wrapping around to z");
verify(logger, times(31)).debug("Wrapping around to a");
verify(logger, times(45)).debug(eq("Encoded character {}"), anyChar());
verify(logger, times(1)).debug("Saving encoded string '{}'", encodedString);
verify(logger, times(1)).debug("Saving encoded string '{}'", ENCODED_STRING);
}
@Test
public void testEncode_negative(){
cipher.inputString = decodedString;
cipher.shift = shift - 26;
cipher.inputString = DECODED_STRING;
cipher.shift = SHIFT - 26;
cipher.encode();
assertEquals(encodedString, cipher.outputString);
assertEquals(ENCODED_STRING, cipher.outputString);
verify(logger, times(1)).debug("Encoding");
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
verify(logger, times(2)).debug("Encoding uppercase");
@@ -245,17 +241,17 @@ public class CaesarTest{
verify(logger, times(2)).debug("Wrapping around to z");
verify(logger, never()).debug("Wrapping around to a");
verify(logger, times(45)).debug(eq("Encoded character {}"), anyChar());
verify(logger, times(1)).debug("Saving encoded string '{}'", encodedString);
verify(logger, times(1)).debug("Saving encoded string '{}'", ENCODED_STRING);
}
@Test
public void testDecode(){
cipher.inputString = encodedString;
cipher.shift = shift;
cipher.inputString = ENCODED_STRING;
cipher.shift = SHIFT;
cipher.decode();
assertEquals(decodedString, cipher.outputString);
assertEquals(DECODED_STRING, cipher.outputString);
verify(logger, times(1)).debug("Decoding");
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
verify(logger, times(2)).debug("Decoding uppercase");
@@ -265,17 +261,17 @@ public class CaesarTest{
verify(logger, times(31)).debug("Wrapping around to z");
verify(logger, never()).debug("Wrapping around to a");
verify(logger, times(45)).debug(eq("Decoded character {}"), anyChar());
verify(logger, times(1)).debug("Saving decoded string '{}'", decodedString);
verify(logger, times(1)).debug("Saving decoded string '{}'", DECODED_STRING);
}
@Test
public void testDecode_negative(){
cipher.inputString = encodedString;
cipher.shift = shift - 26;
cipher.inputString = ENCODED_STRING;
cipher.shift = SHIFT - 26;
cipher.decode();
assertEquals(decodedString, cipher.outputString);
assertEquals(DECODED_STRING, cipher.outputString);
verify(logger, times(1)).debug("Decoding");
verify(logger, times(45)).debug(eq("Working character {}"), anyChar());
verify(logger, times(2)).debug("Decoding uppercase");
@@ -285,25 +281,25 @@ public class CaesarTest{
verify(logger, never()).debug("Wrapping around to z");
verify(logger, times(2)).debug("Wrapping around to a");
verify(logger, times(45)).debug(eq("Decoded character {}"), anyChar());
verify(logger, times(1)).debug("Saving decoded string '{}'", decodedString);
verify(logger, times(1)).debug("Saving decoded string '{}'", DECODED_STRING);
}
@Test
public void testGetters(){
cipher.inputString = decodedString;
cipher.outputString = encodedString;
cipher.shift = shift;
cipher.inputString = DECODED_STRING;
cipher.outputString = ENCODED_STRING;
cipher.shift = SHIFT;
assertEquals(decodedString, cipher.getInputString());
assertEquals(encodedString, cipher.getOutputString());
assertEquals(shift, cipher.getShift());
assertEquals(DECODED_STRING, cipher.getInputString());
assertEquals(ENCODED_STRING, cipher.getOutputString());
assertEquals(SHIFT, cipher.getShift());
}
@Test
public void testReset(){
cipher.inputString = decodedString;
cipher.outputString = encodedString;
cipher.shift = shift;
cipher.inputString = DECODED_STRING;
cipher.outputString = ENCODED_STRING;
cipher.shift = SHIFT;
cipher.reset();
@@ -317,70 +313,70 @@ public class CaesarTest{
public void testPracticalEncoding(){
cipher = new Caesar(true, true, true);
String output = cipher.encode(shift, decodedString);
String output = cipher.encode(SHIFT, DECODED_STRING);
assertEquals(decodedString, cipher.inputString);
assertEquals(shift, cipher.shift);
assertEquals(encodedString, cipher.outputString);
assertEquals(encodedString, output);
assertEquals(DECODED_STRING, cipher.inputString);
assertEquals(SHIFT, cipher.shift);
assertEquals(ENCODED_STRING, cipher.outputString);
assertEquals(ENCODED_STRING, output);
}
@Test
public void testPracticalEncoding_clean(){
cipher = new Caesar(false, false, false);
String output = cipher.encode(shift, decodedString);
String output = cipher.encode(SHIFT, DECODED_STRING);
assertEquals(decodedStringClean, cipher.inputString);
assertEquals(shift, cipher.shift);
assertEquals(encodedStringClean, cipher.outputString);
assertEquals(encodedStringClean, output);
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
assertEquals(SHIFT, cipher.shift);
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
assertEquals(ENCODED_STRING_CLEAN, output);
}
@Test
public void testPracticalEncoding_negative(){
cipher = new Caesar(true, true, true);
String output = cipher.encode(shift, decodedString);
String output = cipher.encode(-3, DECODED_STRING);
assertEquals(decodedString, cipher.inputString);
assertEquals(shift, cipher.shift);
assertEquals(encodedString, cipher.outputString);
assertEquals(encodedString, output);
assertEquals(DECODED_STRING, cipher.inputString);
assertEquals(SHIFT, cipher.shift);
assertEquals(ENCODED_STRING, cipher.outputString);
assertEquals(ENCODED_STRING, output);
}
@Test
public void testPracticalDecoding(){
cipher = new Caesar(true, true, true);
String output = cipher.decode(shift, encodedString);
String output = cipher.decode(SHIFT, ENCODED_STRING);
assertEquals(encodedString, cipher.inputString);
assertEquals(shift, cipher.shift);
assertEquals(decodedString, cipher.outputString);
assertEquals(decodedString, output);
assertEquals(ENCODED_STRING, cipher.inputString);
assertEquals(SHIFT, cipher.shift);
assertEquals(DECODED_STRING, cipher.outputString);
assertEquals(DECODED_STRING, output);
}
@Test
public void testPracticalDecoding_clean(){
cipher = new Caesar(false, false, false);
String output = cipher.decode(shift, encodedString);
String output = cipher.decode(SHIFT, ENCODED_STRING);
assertEquals(encodedStringClean, cipher.inputString);
assertEquals(shift, cipher.shift);
assertEquals(decodedStringClean, cipher.outputString);
assertEquals(decodedStringClean, output);
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
assertEquals(SHIFT, cipher.shift);
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
assertEquals(DECODED_STRING_CLEAN, output);
}
@Test
public void testPracticalDecoding_negative(){
cipher = new Caesar(true, true, true);
String output = cipher.decode(shift - 26, encodedString);
String output = cipher.decode(SHIFT - 26, ENCODED_STRING);
assertEquals(encodedString, cipher.inputString);
assertEquals(shift - 26, cipher.shift);
assertEquals(decodedString, cipher.outputString);
assertEquals(decodedString, output);
assertEquals(ENCODED_STRING, cipher.inputString);
assertEquals(SHIFT, cipher.shift);
assertEquals(DECODED_STRING, cipher.outputString);
assertEquals(DECODED_STRING, output);
}
}