|
@@ -1,5 +1,7 @@
|
1
|
1
|
import org.junit.Test;
|
2
|
2
|
|
|
3
|
+import java.io.File;
|
|
4
|
+
|
3
|
5
|
import static org.junit.Assert.*;
|
4
|
6
|
|
5
|
7
|
public class ROT13Test {
|
|
@@ -87,5 +89,76 @@ public class ROT13Test {
|
87
|
89
|
// Then
|
88
|
90
|
assertTrue(actual.equals(Q1));
|
89
|
91
|
}
|
|
92
|
+ @Test
|
|
93
|
+ public void fileReadTest(){
|
|
94
|
+ ROT13 fileCipher = new ROT13();
|
|
95
|
+
|
|
96
|
+ String file = "Shall I compare thee to a summer’s day?\n" +
|
|
97
|
+ "Thou art more lovely and more temperate:\n" +
|
|
98
|
+ "Rough winds do shake the darling buds of May,\n" +
|
|
99
|
+ "And summer’s lease hath all too short a date;\n" +
|
|
100
|
+ "Sometime too hot the eye of heaven shines,\n" +
|
|
101
|
+ "And often is his gold complexion dimm'd;\n" +
|
|
102
|
+ "And every fair from fair sometime declines,\n" +
|
|
103
|
+ "By chance or nature’s changing course untrimm'd;\n" +
|
|
104
|
+ "But thy eternal summer shall not fade,\n" +
|
|
105
|
+ "Nor lose possession of that fair thou ow’st;\n" +
|
|
106
|
+ "Nor shall death brag thou wander’st in his shade,\n" +
|
|
107
|
+ "When in eternal lines to time thou grow’st:\n" +
|
|
108
|
+ " So long as men can breathe or eyes can see,\n" +
|
|
109
|
+ " So long lives this, and this gives life to thee.";
|
|
110
|
+ String read = fileCipher.fileReader("/Users/roym/labs_week3/ZCW-SimpleCrypt0/sonnet18.txt");
|
|
111
|
+ //String actual = fileCipher.crypt(read);
|
|
112
|
+ assertEquals(file, read);
|
|
113
|
+
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ @Test
|
|
117
|
+ public void encryptTest(){
|
|
118
|
+ ROT13 fileCipher = new ROT13();
|
|
119
|
+ String file = "Shall I compare thee to a summer’s day?\n" +
|
|
120
|
+ "Thou art more lovely and more temperate:\n" +
|
|
121
|
+ "Rough winds do shake the darling buds of May,\n" +
|
|
122
|
+ "And summer’s lease hath all too short a date;\n" +
|
|
123
|
+ "Sometime too hot the eye of heaven shines,\n" +
|
|
124
|
+ "And often is his gold complexion dimm'd;\n" +
|
|
125
|
+ "And every fair from fair sometime declines,\n" +
|
|
126
|
+ "By chance or nature’s changing course untrimm'd;\n" +
|
|
127
|
+ "But thy eternal summer shall not fade,\n" +
|
|
128
|
+ "Nor lose possession of that fair thou ow’st;\n" +
|
|
129
|
+ "Nor shall death brag thou wander’st in his shade,\n" +
|
|
130
|
+ "When in eternal lines to time thou grow’st:\n" +
|
|
131
|
+ " So long as men can breathe or eyes can see,\n" +
|
|
132
|
+ " So long lives this, and this gives life to thee.";
|
|
133
|
+ String expected = fileCipher.encrypt(file);
|
|
134
|
+ String read = fileCipher.fileReader("/Users/roym/labs_week3/ZCW-SimpleCrypt0/sonnet18.txt");
|
|
135
|
+ String actual = fileCipher.encrypt(read);
|
|
136
|
+ fileCipher.fileWrite(actual);
|
|
137
|
+
|
|
138
|
+ assertEquals(expected, actual);
|
|
139
|
+ }
|
|
140
|
+
|
|
141
|
+ @Test
|
|
142
|
+ public void fileDecrypt(){
|
|
143
|
+ ROT13 fileCipher = new ROT13();
|
|
144
|
+ String expected = "Shall I compare thee to a summer’s day?\n" +
|
|
145
|
+ "Thou art more lovely and more temperate:\n" +
|
|
146
|
+ "Rough winds do shake the darling buds of May,\n" +
|
|
147
|
+ "And summer’s lease hath all too short a date;\n" +
|
|
148
|
+ "Sometime too hot the eye of heaven shines,\n" +
|
|
149
|
+ "And often is his gold complexion dimm'd;\n" +
|
|
150
|
+ "And every fair from fair sometime declines,\n" +
|
|
151
|
+ "By chance or nature’s changing course untrimm'd;\n" +
|
|
152
|
+ "But thy eternal summer shall not fade,\n" +
|
|
153
|
+ "Nor lose possession of that fair thou ow’st;\n" +
|
|
154
|
+ "Nor shall death brag thou wander’st in his shade,\n" +
|
|
155
|
+ "When in eternal lines to time thou grow’st:\n" +
|
|
156
|
+ " So long as men can breathe or eyes can see,\n" +
|
|
157
|
+ " So long lives this, and this gives life to thee.";
|
|
158
|
+ String read = fileCipher.fileReader("/Users/roym/labs_week3/ZCW-SimpleCrypt0/sonnet18.enc");
|
|
159
|
+ String actual = fileCipher.decrypt(read);
|
|
160
|
+ assertEquals(expected, actual);
|
|
161
|
+ }
|
|
162
|
+
|
90
|
163
|
|
91
|
164
|
}
|