A few notes on how to test this (warning of personal opinion :-))
- If you write unit tests, avoid reading the expected results from the files, as this slows down the testing (unit tests should be very fast), and also create another thing that is not related to your code that may go wrong (i.e. file can be deleted, etc.)
- , , , . ,
- , Java - , ( - Java 8, ), ,
(?) . , (, , . SRP). , - .
:
@Test
public void testThatEncryptingStringResultsInExpectedBytes() {
byte[] encryption = enigma.encryptString(TEST_STRING);
assertArrayEquals(EXPECTED_ENCRYPTION, encryption);
}
@Test
public void testThatDecryptinEncryptionResultsInOriginalString() {
String decryption = enigma.decryptBytes(TEST_ENCRYPTION);
assertEquals(EXPECTED_ORIGINAL_STRING, decryption);
}
@Test
public void testThatDecriptionReversesEncryption() {
String decryption = enigma.decryptBytes(enigma.encryptString(TEST_STRING));
assertEquals(TEST_STRING, decryption);
}
@Test
public void testThatEncryptionReversesDecryption() {
byte[] encryption = enigma.encriptString(enigma.decryptBytes(TEST_ENCRYPTION));
assertEquals(TEST_ENCRYPTION, encryption);
}
, , , / .