import org.junit.Assert; import org.junit.Test; import static org.junit.Assert.*; public class CaesarTest { @Test public void rotateStringTest0() { // Given String s1 = "ABCDEF"; String s2 = "ABCDEF"; // When Caesar cipher = new Caesar(); String actual = cipher.rotateByNumber(s1, 0); // Then assertTrue(actual.equals(s2)); } @Test public void rotateStringTest1() { // Given String s1 = "ABCDEF"; String s2 = "DEFABC"; // When Caesar cipher = new Caesar(); String actual = cipher.rotateByNumber(s1, 3); // Then assertTrue(actual.equals(s2)); } @Test public void rotateStringTest2() { // Given String s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String s2 = "NOPQRSTUVWXYZABCDEFGHIJKLM"; // When Caesar cipher = new Caesar(); String actual = cipher.rotateByNumber(s1, 13); System.out.println(s1); System.out.println(actual); // Then assertTrue(actual.equals(s2)); } @Test public void cryptTest1() { // Given Caesar cipher = new Caesar(13); String Q1 = "Why did the chicken cross the road?"; String A1 = "Jul qvq gur puvpxra pebff gur ebnq?"; String Q2 = "Gb trg gb gur bgure fvqr!"; String A2 = "To get to the other side!"; // When String actual = cipher.encrypt(Q1); System.out.println(Q1); System.out.println(A1); // Then Assert.assertEquals(A1, actual); // When String actual2 = cipher.decrypt(Q2); System.out.println(Q2); System.out.println(A2); // Then Assert.assertEquals(A2, actual2); } @Test public void cryptTest2() { // Given Caesar cipher = new Caesar(4); String Q1 = "This is a test of Caesar."; String A1 = "Xlmw mw e xiwx sj geiwev."; String Q2 = "Ynulpo wna bqj!"; String A2 = "Crypts are fun!"; // When String actual = cipher.encrypt(Q1); System.out.println(Q1); System.out.println(A1); // Then Assert.assertEquals(A1, actual); // When String actual2 = cipher.decrypt(Q2); System.out.println(Q2); System.out.println(A2); // Then Assert.assertEquals(A2, actual2); } }