Skip to content

Commit 18e3230

Browse files
authored
Remove nested test classes from practice exercise simple-cipher (exercism#2538) (exercism#2545)
* Remove nested test classes from practice exercise simple-cipher * Renamed non-ambiguous test method Fixes exercism#2538
1 parent c5660c7 commit 18e3230

1 file changed

Lines changed: 81 additions & 90 deletions

File tree

Lines changed: 81 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,104 @@
11
import org.junit.Before;
22
import org.junit.Ignore;
33
import org.junit.Test;
4-
import org.junit.experimental.runners.Enclosed;
5-
import org.junit.runner.RunWith;
64

75
import static org.assertj.core.api.Assertions.assertThat;
86

9-
10-
@RunWith(Enclosed.class)
117
public class SimpleCipherTest {
12-
public static class RandomKeyCipher {
13-
private Cipher cipherWithDefaultKey;
14-
15-
@Before
16-
public void setup() {
17-
cipherWithDefaultKey = new Cipher();
18-
}
8+
private Cipher randomKeyCipher;
9+
private Cipher substitutionCipher = new Cipher("abcdefghij");
1910

20-
/**
21-
* Here we take advantage of the fact that plaintext of "aaa..." doesn't output the key. This is a critical
22-
* problem with shift ciphers, some characters will always output the key verbatim.
23-
*/
24-
@Test
25-
public void cipherCanEncode() {
26-
String plainText = "aaaaaaaaaa";
27-
String cipherText = cipherWithDefaultKey.getKey().substring(0, 10);
28-
assertThat(cipherWithDefaultKey.encode(plainText)).isEqualTo(cipherText);
29-
}
11+
@Before
12+
public void setup() {
13+
randomKeyCipher = new Cipher();
14+
}
3015

31-
@Ignore("Remove to run test")
32-
@Test
33-
public void cipherCanDecode() {
34-
String cipherText = "aaaaaaaaaa";
35-
assertThat(cipherWithDefaultKey.decode(cipherWithDefaultKey.getKey().substring(0, 10)))
36-
.isEqualTo(cipherText);
37-
}
16+
/**
17+
* Here we take advantage of the fact that plaintext of "aaa..." doesn't output the key. This is a critical
18+
* problem with shift ciphers, some characters will always output the key verbatim.
19+
*/
20+
@Test
21+
public void randomKeyCipherCanEncode() {
22+
String plainText = "aaaaaaaaaa";
23+
String cipherText = randomKeyCipher.getKey().substring(0, 10);
24+
assertThat(randomKeyCipher.encode(plainText)).isEqualTo(cipherText);
25+
}
3826

39-
@Ignore("Remove to run test")
40-
@Test
41-
public void cipherIsReversible() {
42-
String plainText = "abcdefghij";
43-
assertThat(cipherWithDefaultKey.decode(cipherWithDefaultKey.encode(plainText))).isEqualTo(plainText);
44-
}
27+
@Ignore("Remove to run test")
28+
@Test
29+
public void randomKeyCipherCanDecode() {
30+
String cipherText = "aaaaaaaaaa";
31+
assertThat(randomKeyCipher.decode(randomKeyCipher.getKey().substring(0, 10)))
32+
.isEqualTo(cipherText);
33+
}
4534

46-
@Ignore("Remove to run test")
47-
@Test
48-
public void keyIsLowercaseLetters() {
49-
assertThat(cipherWithDefaultKey.getKey()).matches("^[a-z]+$");
50-
}
35+
@Ignore("Remove to run test")
36+
@Test
37+
public void randomKeyCipherIsReversible() {
38+
String plainText = "abcdefghij";
39+
assertThat(randomKeyCipher.decode(randomKeyCipher.encode(plainText))).isEqualTo(plainText);
5140
}
5241

53-
public static class SubstitutionCipher {
54-
private Cipher cipherWithDefaultKey = new Cipher("abcdefghij");
42+
@Ignore("Remove to run test")
43+
@Test
44+
public void randomKeyCipherKeyIsLowercaseLetters() {
45+
assertThat(randomKeyCipher.getKey()).matches("^[a-z]+$");
46+
}
5547

56-
@Ignore("Remove to run test")
57-
@Test
58-
public void cipherCanEncode() {
59-
String plainText = "aaaaaaaaaa";
60-
String cipherText = "abcdefghij";
61-
assertThat(cipherWithDefaultKey.encode(plainText)).isEqualTo(cipherText);
62-
}
48+
@Ignore("Remove to run test")
49+
@Test
50+
public void substitutionCipherCanEncode() {
51+
String plainText = "aaaaaaaaaa";
52+
String cipherText = "abcdefghij";
53+
assertThat(substitutionCipher.encode(plainText)).isEqualTo(cipherText);
54+
}
6355

64-
@Ignore("Remove to run test")
65-
@Test
66-
public void cipherCanDecode() {
67-
String plainText = "abcdefghij";
68-
String cipherText = "aaaaaaaaaa";
69-
assertThat(cipherWithDefaultKey.decode(plainText)).isEqualTo(cipherText);
70-
}
56+
@Ignore("Remove to run test")
57+
@Test
58+
public void substitutionCipherCanDecode() {
59+
String plainText = "abcdefghij";
60+
String cipherText = "aaaaaaaaaa";
61+
assertThat(substitutionCipher.decode(plainText)).isEqualTo(cipherText);
62+
}
7163

72-
@Ignore("Remove to run test")
73-
@Test
74-
public void cipherIsReversibleGivenKey() {
75-
String plainText = "abcdefghij";
76-
assertThat(cipherWithDefaultKey.decode(cipherWithDefaultKey.encode(plainText))).isEqualTo(plainText);
77-
}
64+
@Ignore("Remove to run test")
65+
@Test
66+
public void substitutionCipherIsReversibleGivenKey() {
67+
String plainText = "abcdefghij";
68+
assertThat(substitutionCipher.decode(substitutionCipher.encode(plainText))).isEqualTo(plainText);
69+
}
7870

79-
@Ignore("Remove to run test")
80-
@Test
81-
public void cipherCanDoubleShiftEncode() {
82-
String plainText = "iamapandabear";
83-
String cipherText = "qayaeaagaciai";
84-
assertThat(new Cipher(plainText).encode(plainText)).isEqualTo(cipherText);
85-
}
71+
@Ignore("Remove to run test")
72+
@Test
73+
public void substitutionCipherCanDoubleShiftEncode() {
74+
String plainText = "iamapandabear";
75+
String cipherText = "qayaeaagaciai";
76+
assertThat(new Cipher(plainText).encode(plainText)).isEqualTo(cipherText);
77+
}
8678

87-
@Ignore("Remove to run test")
88-
@Test
89-
public void cipherCanWrapEncode() {
90-
String plainText = "zzzzzzzzzz";
91-
String cipherText = "zabcdefghi";
92-
assertThat(cipherWithDefaultKey.encode(plainText)).isEqualTo(cipherText);
93-
}
79+
@Ignore("Remove to run test")
80+
@Test
81+
public void substitutionCipherCanWrapEncode() {
82+
String plainText = "zzzzzzzzzz";
83+
String cipherText = "zabcdefghi";
84+
assertThat(substitutionCipher.encode(plainText)).isEqualTo(cipherText);
85+
}
9486

95-
@Ignore("Remove to run test")
96-
@Test
97-
public void cipherCanWrapDecode() {
98-
String plainText = "zabcdefghi";
99-
String cipherText = "zzzzzzzzzz";
100-
assertThat(cipherWithDefaultKey.decode(plainText)).isEqualTo(cipherText);
101-
}
87+
@Ignore("Remove to run test")
88+
@Test
89+
public void substitutionCipherCanWrapDecode() {
90+
String plainText = "zabcdefghi";
91+
String cipherText = "zzzzzzzzzz";
92+
assertThat(substitutionCipher.decode(plainText)).isEqualTo(cipherText);
93+
}
10294

103-
@Ignore("Remove to run test")
104-
@Test
105-
public void cipherMessageLongerThanKey() {
106-
String plainText = "iamapandabear";
107-
String key = "abc";
108-
String cipherText = "iboaqcnecbfcr";
109-
assertThat(new Cipher(key).encode(plainText)).isEqualTo(cipherText);
110-
}
95+
@Ignore("Remove to run test")
96+
@Test
97+
public void substitutionCipherMessageLongerThanKey() {
98+
String plainText = "iamapandabear";
99+
String key = "abc";
100+
String cipherText = "iboaqcnecbfcr";
101+
assertThat(new Cipher(key).encode(plainText)).isEqualTo(cipherText);
111102
}
112103
}
113104

0 commit comments

Comments
 (0)