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

SimpleCipherStepThreeTest.java 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import org.junit.Ignore;
  2. import org.junit.Rule;
  3. import org.junit.Test;
  4. import org.junit.rules.ExpectedException;
  5. import static org.junit.Assert.*;
  6. /**
  7. * Step 3: Generate random key if key isn't specified. Check key is right format
  8. */
  9. public class SimpleCipherStepThreeTest {
  10. @Rule
  11. public ExpectedException expectedException = ExpectedException.none();
  12. @Ignore("Remove to run test")
  13. @Test
  14. public void cipherKeyIsMadeOfLetters() {
  15. assertTrue(new Cipher().getKey().matches("[a-z]+"));
  16. }
  17. @Ignore("Remove to run test")
  18. @Test
  19. public void defaultCipherKeyIs100Characters() {
  20. assertEquals(100, new Cipher().getKey().length());
  21. }
  22. @Ignore("Remove to run test")
  23. @Test
  24. public void cipherKeysAreRandomlyGenerated() {
  25. String newKey = new Cipher().getKey();
  26. assertFalse("Cipher constructor without argument should generate a random key. No two calls to the" +
  27. " constructor should generate the same key. Two calls to the constructor " +
  28. "both returned key: " + newKey, newKey.equals(new Cipher().getKey()));
  29. }
  30. @Ignore("Remove to run test")
  31. @Test
  32. public void cipherThrowsWithAllCapsKey() {
  33. expectedException.expect(IllegalArgumentException.class);
  34. new Cipher("ABCDEF");
  35. }
  36. @Ignore("Remove to run test")
  37. @Test
  38. public void cipherThrowsWithAnyCapsKey() {
  39. expectedException.expect(IllegalArgumentException.class);
  40. new Cipher("abcdEFg");
  41. }
  42. @Ignore("Remove to run test")
  43. @Test
  44. public void cipherThrowsWithNumericKey() {
  45. expectedException.expect(IllegalArgumentException.class);
  46. new Cipher("12345");
  47. }
  48. @Ignore("Remove to run test")
  49. @Test
  50. public void cipherThrowsWithAnyNumericKey() {
  51. expectedException.expect(IllegalArgumentException.class);
  52. new Cipher("abcd345ef");
  53. }
  54. }