|
@@ -0,0 +1,57 @@
|
|
1
|
+import io.zipcoder.Copier;
|
|
2
|
+import io.zipcoder.SafeCopier;
|
|
3
|
+import org.junit.Assert;
|
|
4
|
+import org.junit.Test;
|
|
5
|
+
|
|
6
|
+import java.io.ByteArrayOutputStream;
|
|
7
|
+import java.io.PrintStream;
|
|
8
|
+
|
|
9
|
+public class SafeCopierTest {
|
|
10
|
+
|
|
11
|
+ @Test
|
|
12
|
+ public void outputTest() {
|
|
13
|
+ Copier safeCopier = new SafeCopier("It was the best of times,\n" +
|
|
14
|
+ "it was the blurst of times,\n" +
|
|
15
|
+ "it was the age of wisdom,\n" +
|
|
16
|
+ "it was the age of foolishness,\n" +
|
|
17
|
+ "it was the epoch of belief,\n" +
|
|
18
|
+ "it was the epoch of incredulity,\n" +
|
|
19
|
+ "it was the season of Light,\n" +
|
|
20
|
+ "it was the season of Darkness,\n" +
|
|
21
|
+ "it was the spring of hope,\n" +
|
|
22
|
+ "it was the winter of despair,\n" +
|
|
23
|
+ "we had everything before us,\n" +
|
|
24
|
+ "we had nothing before us,\n" +
|
|
25
|
+ "we were all going direct to Heaven,\n" +
|
|
26
|
+ "we were all going direct the other way--\n" +
|
|
27
|
+ "in short, the period was so far like the present period, that some of\n" +
|
|
28
|
+ "its noisiest authorities insisted on its being received, for good or for\n" +
|
|
29
|
+ "evil, in the superlative degree of comparison only.");
|
|
30
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
31
|
+ System.setOut(new PrintStream(outputStream));
|
|
32
|
+ while (safeCopier.stringIterator.hasNext()) {
|
|
33
|
+ for (int i = 0; i < 5; i++) {
|
|
34
|
+ Thread monkey = new Thread(safeCopier);
|
|
35
|
+ monkey.start();
|
|
36
|
+ }
|
|
37
|
+ }
|
|
38
|
+ Assert.assertEquals(safeCopier.copied, "It was the best of times,\n" +
|
|
39
|
+ "it was the blurst of times,\n" +
|
|
40
|
+ "it was the age of wisdom,\n" +
|
|
41
|
+ "it was the age of foolishness,\n" +
|
|
42
|
+ "it was the epoch of belief,\n" +
|
|
43
|
+ "it was the epoch of incredulity,\n" +
|
|
44
|
+ "it was the season of Light,\n" +
|
|
45
|
+ "it was the season of Darkness,\n" +
|
|
46
|
+ "it was the spring of hope,\n" +
|
|
47
|
+ "it was the winter of despair,\n" +
|
|
48
|
+ "we had everything before us,\n" +
|
|
49
|
+ "we had nothing before us,\n" +
|
|
50
|
+ "we were all going direct to Heaven,\n" +
|
|
51
|
+ "we were all going direct the other way--\n" +
|
|
52
|
+ "in short, the period was so far like the present period, that some of\n" +
|
|
53
|
+ "its noisiest authorities insisted on its being received, for good or for\n" +
|
|
54
|
+ "evil, in the superlative degree of comparison only.");
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+}
|