lots of exercises in java... from https://github.com/exercism/java

SimpleCipherStepTwoTest.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import org.junit.Before;
  2. import org.junit.Ignore;
  3. import org.junit.Rule;
  4. import org.junit.Test;
  5. import org.junit.rules.ExpectedException;
  6. import static org.junit.Assert.assertEquals;
  7. /**
  8. * Step 2: Specify key and use that for shift distance : substitution cipher
  9. */
  10. public class SimpleCipherStepTwoTest {
  11. private Cipher cipherWithSetKey;
  12. private static final String key = "abcdefghij";
  13. @Rule
  14. public ExpectedException expectedException = ExpectedException.none();
  15. @Before
  16. public void setup() {
  17. cipherWithSetKey = new Cipher(key);
  18. }
  19. @Ignore("Remove to run test")
  20. @Test
  21. public void cipherKeepsTheSubmittedKey() {
  22. assertEquals(key, cipherWithSetKey.getKey());
  23. }
  24. @Ignore("Remove to run test")
  25. @Test
  26. public void cipherThrowsWithEmptyKey() {
  27. expectedException.expect(IllegalArgumentException.class);
  28. new Cipher("");
  29. }
  30. @Ignore("Remove to run test")
  31. @Test
  32. public void cipherCanEncodeWithGivenKey() {
  33. String cipherText = "abcdefghij";
  34. assertEquals(cipherText, cipherWithSetKey.encode("aaaaaaaaaa"));
  35. }
  36. @Ignore("Remove to run test")
  37. @Test
  38. public void cipherCanDecodeWithGivenKey() {
  39. String cipherText = "aaaaaaaaaa";
  40. assertEquals(cipherText, cipherWithSetKey.decode("abcdefghij"));
  41. }
  42. @Ignore("Remove to run test")
  43. @Test
  44. public void cipherIsReversibleGivenKey() {
  45. String plainText = "abcdefghij";
  46. assertEquals(plainText, cipherWithSetKey.decode(cipherWithSetKey.encode("abcdefghij")));
  47. }
  48. @Ignore("Remove to run test")
  49. @Test
  50. public void cipherCanWrapEncode() {
  51. String cipherText = "zabcdefghi";
  52. assertEquals(cipherText, cipherWithSetKey.encode("zzzzzzzzzz"));
  53. }
  54. @Ignore("Remove to run test")
  55. @Test
  56. public void cipherCanEncodeMessageThatIsShorterThanTheKey() {
  57. String cipherText = "abcde";
  58. assertEquals(cipherText, cipherWithSetKey.encode("aaaaa"));
  59. }
  60. @Ignore("Remove to run test")
  61. @Test
  62. public void cipherCanDecodeMessageThatIsShorterThanTheKey() {
  63. String cipherText = "aaaaa";
  64. assertEquals(cipherText, cipherWithSetKey.decode("abcde"));
  65. }
  66. @Ignore("Remove to run test")
  67. @Test
  68. public void cipherCanDoubleShiftEncode() {
  69. String plainText = "iamapandabear";
  70. String cipherText = "qayaeaagaciai";
  71. assertEquals(cipherText, new Cipher(plainText).encode(plainText));
  72. }
  73. }