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/monosubstitution/OneTimePadTest.java
//Mattrixwv
// Created: 02-23-22
//Modified: 05-04-23
package com.mattrixwv.cipherstream.monosubstitution;
@@ -29,12 +25,12 @@ public class OneTimePadTest{
@Mock(name = "com.mattrixwv.cipherstream.monosubstitution.OneTimePad")
private Logger logger;
//Variables
private static final String decodedString = "Message to^encode";
private static final String decodedStringClean = "MESSAGETOENCODE";
private static final String encodedString = "Wiqooxh mv^egkgws";
private static final String encodedStringClean = "WIQOOXHMVEGKGWS";
private static final String keyword = "keywordThatIsTotallyRandom";
private static final 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));
private static final String DECODED_STRING = "Message to^encode";
private static final String DECODED_STRING_CLEAN = "MESSAGETOENCODE";
private static final String ENCODED_STRING = "Wiqooxh mv^egkgws";
private static final String ENCODED_STRING_CLEAN = "WIQOOXHMVEGKGWS";
private static final String KEYWORD = "keywordThatIsTotallyRandom";
private static final 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));
@Test
@@ -95,13 +91,13 @@ public class OneTimePadTest{
cipher.preserveWhitespace = true;
cipher.preserveSymbols = true;
String output = cipher.encode(keyword, decodedString);
String output = cipher.encode(KEYWORD, DECODED_STRING);
assertEquals(decodedString, cipher.inputString);
assertEquals(keyword.toUpperCase(), cipher.keyword);
assertEquals(encodedString, cipher.outputString);
assertEquals(encodedString, output);
assertEquals(offset, cipher.offset);
assertEquals(DECODED_STRING, cipher.inputString);
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
assertEquals(ENCODED_STRING, cipher.outputString);
assertEquals(ENCODED_STRING, output);
assertEquals(OFFSET, cipher.offset);
verify(logger, times(1)).debug("Encoding");
}
@@ -111,13 +107,13 @@ public class OneTimePadTest{
cipher.preserveWhitespace = false;
cipher.preserveSymbols = false;
String output = cipher.encode(keyword, decodedString);
String output = cipher.encode(KEYWORD, DECODED_STRING);
assertEquals(decodedStringClean, cipher.inputString);
assertEquals(keyword.toUpperCase(), cipher.keyword);
assertEquals(encodedStringClean, cipher.outputString);
assertEquals(encodedStringClean, output);
assertEquals(offset, cipher.offset);
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
assertEquals(ENCODED_STRING_CLEAN, output);
assertEquals(OFFSET, cipher.offset);
verify(logger, times(1)).debug("Encoding");
}
@@ -128,7 +124,7 @@ public class OneTimePadTest{
cipher.preserveSymbols = true;
assertThrows(InvalidKeywordException.class, () -> {
cipher.encode("keyword", decodedString);
cipher.encode("keyword", DECODED_STRING);
});
assertEquals("", cipher.inputString);
@@ -144,13 +140,13 @@ public class OneTimePadTest{
cipher.preserveWhitespace = true;
cipher.preserveSymbols = true;
String output = cipher.decode(keyword, encodedString);
String output = cipher.decode(KEYWORD, ENCODED_STRING);
assertEquals(encodedString, cipher.inputString);
assertEquals(keyword.toUpperCase(), cipher.keyword);
assertEquals(decodedString, cipher.outputString);
assertEquals(decodedString, output);
assertEquals(offset, cipher.offset);
assertEquals(ENCODED_STRING, cipher.inputString);
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
assertEquals(DECODED_STRING, cipher.outputString);
assertEquals(DECODED_STRING, output);
assertEquals(OFFSET, cipher.offset);
verify(logger, times(1)).debug("Decoding");
}
@@ -160,20 +156,20 @@ public class OneTimePadTest{
cipher.preserveWhitespace = false;
cipher.preserveSymbols = false;
String output = cipher.decode(keyword, encodedString);
String output = cipher.decode(KEYWORD, ENCODED_STRING);
assertEquals(encodedStringClean, cipher.inputString);
assertEquals(keyword.toUpperCase(), cipher.keyword);
assertEquals(decodedStringClean, cipher.outputString);
assertEquals(decodedStringClean, output);
assertEquals(offset, cipher.offset);
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
assertEquals(DECODED_STRING_CLEAN, output);
assertEquals(OFFSET, cipher.offset);
verify(logger, times(1)).debug("Decoding");
}
@Test
public void testDecode_short(){
assertThrows(InvalidKeywordException.class, () -> {
cipher.decode("keyword", encodedString);
cipher.decode("keyword", ENCODED_STRING);
});
assertEquals("", cipher.inputString);
@@ -187,47 +183,47 @@ public class OneTimePadTest{
public void testPracticalEncoding(){
cipher = new OneTimePad(true, true, true);
String output = cipher.encode(keyword, decodedString);
String output = cipher.encode(KEYWORD, DECODED_STRING);
assertEquals(decodedString, cipher.inputString);
assertEquals(keyword.toUpperCase(), cipher.keyword);
assertEquals(encodedString, cipher.outputString);
assertEquals(encodedString, output);
assertEquals(DECODED_STRING, cipher.inputString);
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
assertEquals(ENCODED_STRING, cipher.outputString);
assertEquals(ENCODED_STRING, output);
}
@Test
public void testPracticalEncoding_clean(){
cipher = new OneTimePad(false, false, false);
String output = cipher.encode(keyword, decodedString);
String output = cipher.encode(KEYWORD, DECODED_STRING);
assertEquals(decodedStringClean, cipher.inputString);
assertEquals(keyword.toUpperCase(), cipher.keyword);
assertEquals(encodedStringClean, cipher.outputString);
assertEquals(encodedStringClean, output);
assertEquals(DECODED_STRING_CLEAN, cipher.inputString);
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
assertEquals(ENCODED_STRING_CLEAN, cipher.outputString);
assertEquals(ENCODED_STRING_CLEAN, output);
}
@Test
public void testPracticalDecoding(){
cipher = new OneTimePad(true, true, true);
String output = cipher.decode(keyword, encodedString);
String output = cipher.decode(KEYWORD, ENCODED_STRING);
assertEquals(encodedString, cipher.inputString);
assertEquals(keyword.toUpperCase(), cipher.keyword);
assertEquals(decodedString, cipher.outputString);
assertEquals(decodedString, output);
assertEquals(ENCODED_STRING, cipher.inputString);
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
assertEquals(DECODED_STRING, cipher.outputString);
assertEquals(DECODED_STRING, output);
}
@Test
public void testPracticalDecoding_clean(){
cipher = new OneTimePad(false, false, false);
String output = cipher.decode(keyword, encodedString);
String output = cipher.decode(KEYWORD, ENCODED_STRING);
assertEquals(encodedStringClean, cipher.inputString);
assertEquals(keyword.toUpperCase(), cipher.keyword);
assertEquals(decodedStringClean, cipher.outputString);
assertEquals(decodedStringClean, output);
assertEquals(ENCODED_STRING_CLEAN, cipher.inputString);
assertEquals(KEYWORD.toUpperCase(), cipher.keyword);
assertEquals(DECODED_STRING_CLEAN, cipher.outputString);
assertEquals(DECODED_STRING_CLEAN, output);
}
}