|
9 | 9 |
|
10 | 10 | public class MonoAlphabeticTest {
|
11 | 11 |
|
12 |
| - private static final String KEY = "MNBVCXZLKJHGFDSAPOIUYTREWQ"; |
13 |
| - |
14 |
| - // Test for encryption |
| 12 | + // Test for both encryption and decryption with different keys |
15 | 13 | @ParameterizedTest
|
16 |
| - @MethodSource("provideEncryptionData") |
17 |
| - public void testEncrypt(String data, String key, String expected) { |
18 |
| - assertEquals(expected, MonoAlphabetic.encrypt(data, key)); |
19 |
| - } |
20 |
| - |
21 |
| - // Test for decryption |
22 |
| - @ParameterizedTest |
23 |
| - @MethodSource("provideDecryptionData") |
24 |
| - public void testDecrypt(String data, String key, String expected) { |
25 |
| - assertEquals(expected, MonoAlphabetic.decrypt(data, key)); |
26 |
| - } |
| 14 | + @MethodSource("provideTestData") |
| 15 | + public void testEncryptDecrypt(String plainText, String key, String encryptedText) { |
| 16 | + // Test encryption |
| 17 | + assertEquals(encryptedText, MonoAlphabetic.encrypt(plainText, key)); |
27 | 18 |
|
28 |
| - // Provide test data for encryption |
29 |
| - private static Stream<Arguments> provideEncryptionData() { |
30 |
| - return Stream.of(Arguments.of("HELLO", KEY, "LCGGS"), Arguments.of("JAVA", KEY, "JMTM")); |
| 19 | + // Test decryption |
| 20 | + assertEquals(plainText, MonoAlphabetic.decrypt(encryptedText, key)); |
31 | 21 | }
|
32 | 22 |
|
33 |
| - // Provide test data for decryption |
34 |
| - private static Stream<Arguments> provideDecryptionData() { |
35 |
| - return Stream.of(Arguments.of("LCGGS", KEY, "HELLO"), Arguments.of("JMTM", KEY, "JAVA")); |
| 23 | + // Provide test data for both encryption and decryption |
| 24 | + private static Stream<Arguments> provideTestData() { |
| 25 | + return Stream.of( |
| 26 | + Arguments.of("HELLO", "MNBVCXZLKJHGFDSAPOIUYTREWQ", "LCGGS"), Arguments.of("JAVA", "MNBVCXZLKJHGFDSAPOIUYTREWQ", "JMTM"), Arguments.of("HELLO", "QWERTYUIOPLKJHGFDSAZXCVBNM", "UJJYU"), Arguments.of("JAVA", "QWERTYUIOPLKJHGFDSAZXCVBNM", "KZHS")); |
36 | 27 | }
|
37 | 28 | }
|
0 commit comments