Leon vor 6 Jahren
Commit
3d70edf1d5

+ 6
- 0
.gitignore Datei anzeigen

@@ -0,0 +1,6 @@
1
+/target/
2
+.DS_Store
3
+.classpath
4
+#.project
5
+.settings
6
+.idea

+ 8
- 0
README.md Datei anzeigen

@@ -0,0 +1,8 @@
1
+# Read and Write Document
2
+* **Objective** - To implement a `Document` object which uses a composite `File` and `FileWriter` to `read` and `write` to a 
3
+* **Purpose** -  To demonstrate use of exception handling
4
+
5
+
6
+
7
+## Instructions
8
+* Ensure each of the test classes passes with 100% pass rate.

+ 0
- 0
file.txt Datei anzeigen


+ 32
- 0
pom.xml Datei anzeigen

@@ -0,0 +1,32 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>rocks.zipcode</groupId>
8
+    <artifactId>readandwrite</artifactId>
9
+    <version>1.0</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>8</source>
17
+                    <target>8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
22
+    <dependencies>
23
+        <dependency>
24
+            <groupId>junit</groupId>
25
+            <artifactId>junit</artifactId>
26
+            <version>4.12</version>
27
+            <scope>test</scope>
28
+        </dependency>
29
+    </dependencies>
30
+
31
+
32
+</project>

+ 16
- 0
readandwrite.iml Datei anzeigen

@@ -0,0 +1,16 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
4
+    <output url="file://$MODULE_DIR$/target/classes" />
5
+    <output-test url="file://$MODULE_DIR$/target/test-classes" />
6
+    <content url="file://$MODULE_DIR$">
7
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9
+      <excludeFolder url="file://$MODULE_DIR$/target" />
10
+    </content>
11
+    <orderEntry type="inheritedJdk" />
12
+    <orderEntry type="sourceFolder" forTests="false" />
13
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
14
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15
+  </component>
16
+</module>

+ 20
- 0
src/main/java/rocks/zipcode/AlphaCharDocument.java Datei anzeigen

@@ -0,0 +1,20 @@
1
+package rocks.zipcode;
2
+
3
+import java.io.IOException;
4
+
5
+/**
6
+ * @author leon on 16/11/2018.
7
+ */
8
+public class AlphaCharDocument extends Document {
9
+    public AlphaCharDocument(String fileName) throws IOException {
10
+        super(fileName);
11
+    }
12
+
13
+    @Override
14
+    public void write(String contentToBeWritten) {
15
+    }
16
+
17
+    private Boolean isAlpha(String s) {
18
+        return null;
19
+    }
20
+}

+ 64
- 0
src/main/java/rocks/zipcode/Document.java Datei anzeigen

@@ -0,0 +1,64 @@
1
+package rocks.zipcode;
2
+
3
+import java.io.*;
4
+import java.nio.file.Files;
5
+import java.util.Arrays;
6
+import java.util.List;
7
+
8
+/**
9
+ * @author leon on 16/11/2018.
10
+ */
11
+public class Document implements DocumentInterface {
12
+
13
+    private final FileWriter fileWriter;
14
+    private final File file;
15
+
16
+    public Document(String fileName) throws IOException {
17
+        this(new File(fileName));
18
+    }
19
+
20
+    public Document(File file) throws IOException {
21
+        this.file = file;
22
+        this.fileWriter = new FileWriter(file);
23
+    }
24
+
25
+    @Override
26
+    public void write(String contentToBeWritten) {
27
+    }
28
+
29
+    @Override
30
+    public void write(Integer lineNumber, String valueToBeWritten) {
31
+    }
32
+
33
+    @Override
34
+    public String read(Integer lineNumber) {
35
+        return null;
36
+    }
37
+
38
+    @Override
39
+    public String read() {
40
+        return null;
41
+    }
42
+
43
+    @Override
44
+    public void replaceAll(String stringToReplace, String replacementString) {
45
+    }
46
+
47
+    @Override
48
+    public void overWrite(String content) {
49
+    }
50
+
51
+    public List<String> toList() {
52
+        return null;
53
+    }
54
+
55
+    @Override
56
+    public File getFile() {
57
+        return null;
58
+    }
59
+
60
+    @Override
61
+    public String toString() {
62
+        return null;
63
+    }
64
+}

+ 28
- 0
src/main/java/rocks/zipcode/DocumentInterface.java Datei anzeigen

@@ -0,0 +1,28 @@
1
+package rocks.zipcode;
2
+
3
+import java.io.File;
4
+import java.util.List;
5
+
6
+/**
7
+ * @author leon on 16/11/2018.
8
+ */
9
+public interface DocumentInterface {
10
+    void write(String contentToBeWritten);
11
+
12
+    void write(Integer lineNumber, String valueToBeWritten);
13
+
14
+    String read(Integer lineNumber);
15
+
16
+    String read();
17
+
18
+    void replaceAll(String stringToReplace, String replacementString);
19
+
20
+    void overWrite(String content);
21
+
22
+    List<String> toList();
23
+
24
+    File getFile();
25
+
26
+    @Override
27
+    String toString();
28
+}

+ 20
- 0
src/main/java/rocks/zipcode/NumericCharDocument.java Datei anzeigen

@@ -0,0 +1,20 @@
1
+package rocks.zipcode;
2
+
3
+import java.io.IOException;
4
+
5
+/**
6
+ * @author leon on 16/11/2018.
7
+ */
8
+public class NumericCharDocument extends Document {
9
+    public NumericCharDocument(String fileName) throws IOException {
10
+        super(fileName);
11
+    }
12
+
13
+    @Override
14
+    public void write(String contentToBeWritten) {
15
+    }
16
+
17
+    private Boolean isNumeric(String s) {
18
+        return null;
19
+    }
20
+}

+ 20
- 0
src/main/java/rocks/zipcode/SpecialCharDocument.java Datei anzeigen

@@ -0,0 +1,20 @@
1
+package rocks.zipcode;
2
+
3
+import java.io.IOException;
4
+
5
+/**
6
+ * @author leon on 18/11/2018.
7
+ */
8
+public class SpecialCharDocument extends Document {
9
+    public SpecialCharDocument(String fileName) throws IOException {
10
+        super(fileName);
11
+    }
12
+
13
+    @Override
14
+    public void write(String contentToBeWritten) {
15
+    }
16
+
17
+    private Boolean isSpecialCharacters(String s) {
18
+        return null;
19
+    }
20
+}

+ 52
- 0
src/test/java/rocks/zipcode/alphadocument/AlphaDocumentWriteTest.java Datei anzeigen

@@ -0,0 +1,52 @@
1
+package rocks.zipcode.alphadocument;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.AlphaCharDocument;
6
+import rocks.zipcode.Document;
7
+
8
+import java.io.IOException;
9
+
10
+/**
11
+ * @author leon on 16/11/2018.
12
+ */
13
+public class AlphaDocumentWriteTest {
14
+
15
+    @Test(expected = IllegalArgumentException.class)
16
+    public void writeNumericValuesToFile() throws IOException {
17
+        // given
18
+        String fileName = "file.txt";
19
+        String contentToBeWritten = "123";
20
+        Document documentWriter = new AlphaCharDocument(fileName);
21
+
22
+        // when
23
+        documentWriter.write(contentToBeWritten);
24
+    }
25
+
26
+    @Test(expected = IllegalArgumentException.class)
27
+    public void writeSpecialCharacter() throws IOException {
28
+        // given
29
+        String fileName = "file.txt";
30
+        String contentToBeWritten = "()";
31
+        Document documentWriter = new AlphaCharDocument(fileName);
32
+
33
+        // when
34
+        documentWriter.write(contentToBeWritten);
35
+    }
36
+
37
+
38
+    @Test
39
+    public void writeAlphaValuesTest() throws IOException {
40
+        // given
41
+        String fileName = "file.txt";
42
+        String expected = "The quick brown foxy";
43
+        Document documentWriter = new AlphaCharDocument(fileName);
44
+
45
+        // when
46
+        documentWriter.write(expected);
47
+        String actual = documentWriter.read();
48
+
49
+        // then
50
+        Assert.assertEquals(expected, actual);
51
+    }
52
+}

+ 46
- 0
src/test/java/rocks/zipcode/document/DocumentOverwriteTest.java Datei anzeigen

@@ -0,0 +1,46 @@
1
+package rocks.zipcode.document;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.Document;
6
+
7
+import java.io.IOException;
8
+
9
+/**
10
+ * @author leon on 16/11/2018.
11
+ */
12
+public class DocumentOverwriteTest {
13
+    @Test
14
+    public void writeTest1() throws IOException {
15
+        // given
16
+        String fileName = "file.txt";
17
+        String contentToBeOverwritten = "The quick brown fox";
18
+        String expected = "The quick browner fox";
19
+        Document documentWriter = new Document(fileName);
20
+        documentWriter.write(contentToBeOverwritten);
21
+
22
+        // when
23
+        documentWriter.overWrite(expected);
24
+        String actual = documentWriter.read();
25
+
26
+        // then
27
+        Assert.assertEquals(expected, actual);
28
+    }
29
+
30
+    @Test
31
+    public void writeTest2() throws IOException {
32
+        // given
33
+        String fileName = "file.txt";
34
+        String contentToBeOverwritten = "The quick brown fox";
35
+        String expected = "The quick brownest fox";
36
+        Document documentWriter = new Document(fileName);
37
+        documentWriter.write(contentToBeOverwritten);
38
+
39
+        // when
40
+        documentWriter.overWrite(expected);
41
+        String actual = documentWriter.read();
42
+
43
+        // then
44
+        Assert.assertEquals(expected, actual);
45
+    }
46
+}

+ 46
- 0
src/test/java/rocks/zipcode/document/DocumentReadLineTest.java Datei anzeigen

@@ -0,0 +1,46 @@
1
+package rocks.zipcode.document;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.Document;
6
+
7
+import java.io.IOException;
8
+
9
+/**
10
+ * @author leon on 16/11/2018.
11
+ */
12
+public class DocumentReadLineTest {
13
+    @Test
14
+    public void testReadFirstLine() throws IOException {
15
+        // given
16
+        String expected = "The";
17
+        String fileName = "file.txt";
18
+        Document documentWriter = new Document(fileName);
19
+        String contentToBeWritten = "The\nquick\nbrown\nfox";
20
+        documentWriter.write(contentToBeWritten);
21
+
22
+        // when
23
+        String actual = documentWriter.read(0);
24
+
25
+        // then
26
+        Assert.assertEquals(expected, actual);
27
+    }
28
+
29
+
30
+    @Test
31
+    public void testReadSecondLine() throws IOException {
32
+        // given
33
+        String expected = "quick";
34
+        String fileName = "file.txt";
35
+        Document documentWriter = new Document(fileName);
36
+        String contentToBeWritten = "The\nquick\nbrown\nfox";
37
+        documentWriter.write(contentToBeWritten);
38
+
39
+        // when
40
+        String actual = documentWriter.read(1);
41
+
42
+        // then
43
+        Assert.assertEquals(expected, actual);
44
+    }
45
+}
46
+

+ 43
- 0
src/test/java/rocks/zipcode/document/DocumentReadTest.java Datei anzeigen

@@ -0,0 +1,43 @@
1
+package rocks.zipcode.document;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.Document;
6
+
7
+import java.io.IOException;
8
+
9
+/**
10
+ * @author leon on 16/11/2018.
11
+ */
12
+public class DocumentReadTest {
13
+    @Test
14
+    public void testRead1() throws IOException {
15
+        // given
16
+        String fileName = "file.txt";
17
+        Document documentWriter = new Document(fileName);
18
+        String expected = "The\nquick\nbrown\nfox";
19
+        documentWriter.write(expected);
20
+
21
+        // when
22
+        String actual = documentWriter.read();
23
+
24
+        // then
25
+        Assert.assertEquals(expected, actual);
26
+    }
27
+
28
+    @Test
29
+    public void testRead2() throws IOException {
30
+        // given
31
+        String fileName = "file.txt";
32
+        Document documentWriter = new Document(fileName);
33
+        String expected = "The\nquicker\nbrown\nfox";
34
+        documentWriter.write(expected);
35
+
36
+        // when
37
+        String actual = documentWriter.read();
38
+
39
+        // then
40
+        Assert.assertEquals(expected, actual);
41
+    }
42
+
43
+}

+ 50
- 0
src/test/java/rocks/zipcode/document/DocumentReplaceAllTest.java Datei anzeigen

@@ -0,0 +1,50 @@
1
+package rocks.zipcode.document;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.Document;
6
+
7
+import java.io.IOException;
8
+
9
+/**
10
+ * @author leon on 16/11/2018.
11
+ */
12
+public class DocumentReplaceAllTest {
13
+    @Test
14
+    public void testReplace_e_withUnderscore() throws IOException {
15
+        // given
16
+        String fileName = "file.txt";
17
+        Document documentWriter = new Document(fileName);
18
+        String contentToBeWritten = "Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit,\nsed do eiusmod tempor incididunt\nut labore et dolore\nmagna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\nnisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate\nvelit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat\nnon proident, sunt in culpa qui officia deserunt mollit anim id est laborum";
19
+        String valueToReplace = "e";
20
+        String replacementValue = "_";
21
+        String expected = contentToBeWritten.replaceAll(valueToReplace, replacementValue);
22
+        documentWriter.write(contentToBeWritten);
23
+
24
+        // when
25
+        documentWriter.replaceAll(valueToReplace, replacementValue);
26
+
27
+        // then
28
+        String actual = documentWriter.read();
29
+        Assert.assertEquals(expected, actual);
30
+    }
31
+
32
+    @Test
33
+    public void testReplace_newLine_withEmptyString() throws IOException {
34
+        // given
35
+        String fileName = "file.txt";
36
+        Document documentWriter = new Document(fileName);
37
+        String contentToBeWritten = "Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit,\nsed do eiusmod tempor incididunt\nut labore et dolore\nmagna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\nnisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate\nvelit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat\nnon proident, sunt in culpa qui officia deserunt mollit anim id est laborum";
38
+        String valueToReplace = "\n";
39
+        String replacementValue = "";
40
+        String expected = contentToBeWritten.replaceAll(valueToReplace, replacementValue);
41
+        documentWriter.write(contentToBeWritten);
42
+
43
+        // when
44
+        documentWriter.replaceAll(valueToReplace, replacementValue);
45
+
46
+        // then
47
+        String actual = documentWriter.read();
48
+        Assert.assertEquals(expected, actual);
49
+    }
50
+}

+ 52
- 0
src/test/java/rocks/zipcode/document/DocumentToStringTest.java Datei anzeigen

@@ -0,0 +1,52 @@
1
+package rocks.zipcode.document;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.Document;
6
+
7
+import java.io.IOException;
8
+
9
+/**
10
+ * @author leon on 16/11/2018.
11
+ */
12
+public class DocumentToStringTest {
13
+    @Test
14
+    public void toStringTest1() throws IOException {
15
+        // given
16
+        String fileName = "file.txt";
17
+        String contentToBeWritten = "The quick brown fox";
18
+        Document documentWriter = new Document(fileName);
19
+        String expected = new StringBuilder(fileName)
20
+                .append("{")
21
+                .append(contentToBeWritten)
22
+                .append("}")
23
+                .toString();
24
+
25
+        // when
26
+        documentWriter.write(contentToBeWritten);
27
+        String actual = documentWriter.toString();
28
+
29
+        // then
30
+        Assert.assertEquals(expected, actual);
31
+    }
32
+
33
+    @Test
34
+    public void toStringTest2() throws IOException {
35
+        // given
36
+        String fileName = "file.txt";
37
+        String contentToBeWritten = "The quicker browner fox";
38
+        Document documentWriter = new Document(fileName);
39
+        String expected = new StringBuilder(fileName)
40
+                .append("{")
41
+                .append(contentToBeWritten)
42
+                .append("}")
43
+                .toString();
44
+
45
+        // when
46
+        documentWriter.write(contentToBeWritten);
47
+        String actual = documentWriter.toString();
48
+
49
+        // then
50
+        Assert.assertEquals(expected, actual);
51
+    }
52
+}

+ 58
- 0
src/test/java/rocks/zipcode/document/DocumentWriteTest.java Datei anzeigen

@@ -0,0 +1,58 @@
1
+package rocks.zipcode.document;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.Document;
6
+
7
+import java.io.IOException;
8
+
9
+/**
10
+ * @author leon on 16/11/2018.
11
+ */
12
+public class DocumentWriteTest {
13
+
14
+    @Test
15
+    public void writeAlphaValuesTest() throws IOException {
16
+        // given
17
+        String fileName = "file.txt";
18
+        String expected = "The quick brown fox";
19
+        Document documentWriter = new Document(fileName);
20
+
21
+        // when
22
+        documentWriter.write(expected);
23
+        String actual = documentWriter.read();
24
+
25
+        // then
26
+        Assert.assertEquals(expected, actual);
27
+    }
28
+
29
+    @Test
30
+    public void writeSpecialCharactersTest() throws IOException {
31
+        // given
32
+        String fileName = "file.txt";
33
+        String expected = "()";
34
+        Document documentWriter = new Document(fileName);
35
+
36
+        // when
37
+        documentWriter.write(expected);
38
+        String actual = documentWriter.read();
39
+
40
+        // then
41
+        Assert.assertEquals(expected, actual);
42
+    }
43
+
44
+    @Test
45
+    public void writeNumericValuesTest() throws IOException {
46
+        // given
47
+        String fileName = "file.txt";
48
+        String expected = "123";
49
+        Document documentWriter = new Document(fileName);
50
+
51
+        // when
52
+        documentWriter.write(expected);
53
+        String actual = documentWriter.read();
54
+
55
+        // then
56
+        Assert.assertEquals(expected, actual);
57
+    }
58
+}

+ 48
- 0
src/test/java/rocks/zipcode/document/DocumentWriteToLineTest.java Datei anzeigen

@@ -0,0 +1,48 @@
1
+package rocks.zipcode.document;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.Document;
6
+
7
+import java.io.IOException;
8
+
9
+/**
10
+ * @author leon on 16/11/2018.
11
+ */
12
+public class DocumentWriteToLineTest {
13
+    @Test
14
+    public void writeToLineTest1() throws IOException {
15
+        // given
16
+        String fileName = "file.txt";
17
+        String contentToBeWritten = "The\nquick\nbrown\nfox";
18
+        String replacement = "quicker";
19
+        String expected = contentToBeWritten.replaceAll("quick", replacement);
20
+
21
+        Document documentWriter = new Document(fileName);
22
+        documentWriter.write(contentToBeWritten);
23
+
24
+        // when
25
+        documentWriter.write(1, replacement);
26
+
27
+        // then
28
+        Assert.assertEquals(expected, documentWriter.read());
29
+    }
30
+
31
+    @Test
32
+    public void writeToLineTest2() throws IOException {
33
+        // given
34
+        String fileName = "file.txt";
35
+        String contentToBeWritten = "The\nquick\nbrown\nfox";
36
+        String replacement = "quickest";
37
+        String expected = contentToBeWritten.replaceAll("The", replacement);
38
+
39
+        Document documentWriter = new Document(fileName);
40
+        documentWriter.write(contentToBeWritten);
41
+
42
+        // when
43
+        documentWriter.write(0, replacement);
44
+
45
+        // then
46
+        Assert.assertEquals(expected, documentWriter.read());
47
+    }
48
+}

+ 52
- 0
src/test/java/rocks/zipcode/numericdocument/NumericDocumentWriteTest.java Datei anzeigen

@@ -0,0 +1,52 @@
1
+package rocks.zipcode.numericdocument;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.Document;
6
+import rocks.zipcode.NumericCharDocument;
7
+
8
+import java.io.IOException;
9
+
10
+/**
11
+ * @author leon on 16/11/2018.
12
+ */
13
+public class NumericDocumentWriteTest {
14
+
15
+    @Test
16
+    public void writeNumericValuesToFile() throws IOException {
17
+        // given
18
+        String fileName = "file.txt";
19
+        String contentToBeWritten = "123";
20
+        Document documentWriter = new NumericCharDocument(fileName);
21
+
22
+        // when
23
+        documentWriter.write(contentToBeWritten);
24
+    }
25
+
26
+    @Test(expected = IllegalArgumentException.class)
27
+    public void writeSpecialCharacter() throws IOException {
28
+        // given
29
+        String fileName = "file.txt";
30
+        String contentToBeWritten = "()";
31
+        Document documentWriter = new NumericCharDocument(fileName);
32
+
33
+        // when
34
+        documentWriter.write(contentToBeWritten);
35
+    }
36
+
37
+    @Test(expected = IllegalArgumentException.class)
38
+    public void writeAlphaValuesTest() throws IOException {
39
+        // given
40
+        String fileName = "file.txt";
41
+        String expected = "The quick brown foxy";
42
+        Document documentWriter = new NumericCharDocument(fileName);
43
+
44
+        // when
45
+        documentWriter.write(expected);
46
+        String actual = documentWriter.read();
47
+
48
+        // then
49
+        Assert.assertEquals(expected, actual);
50
+    }
51
+
52
+}

+ 64
- 0
src/test/java/rocks/zipcode/specialdocument/SpecialCharDocumentTest.java Datei anzeigen

@@ -0,0 +1,64 @@
1
+package rocks.zipcode.specialdocument;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.Document;
6
+import rocks.zipcode.SpecialCharDocument;
7
+
8
+import java.io.IOException;
9
+
10
+/**
11
+ * @author leon on 18/11/2018.
12
+ */
13
+public class SpecialCharDocumentTest {
14
+
15
+    @Test(expected = IllegalArgumentException.class)
16
+    public void writeNumericValuesToFile() throws IOException {
17
+        // given
18
+        String fileName = "file.txt";
19
+        String contentToBeWritten = "123";
20
+        Document documentWriter = new SpecialCharDocument(fileName);
21
+
22
+        // when
23
+        documentWriter.write(contentToBeWritten);
24
+    }
25
+
26
+    @Test
27
+    public void writeSpecialCharacter1() throws IOException {
28
+        // given
29
+        String fileName = "file.txt";
30
+        String contentToBeWritten = "()";
31
+        Document documentWriter = new SpecialCharDocument(fileName);
32
+
33
+        // when
34
+        documentWriter.write(contentToBeWritten);
35
+    }
36
+
37
+
38
+    @Test
39
+    public void writeSpecialCharacter2() throws IOException {
40
+        // given
41
+        String fileName = "file.txt";
42
+        String contentToBeWritten = "()_*";
43
+        Document documentWriter = new SpecialCharDocument(fileName);
44
+
45
+        // when
46
+        documentWriter.write(contentToBeWritten);
47
+    }
48
+
49
+
50
+    @Test(expected = IllegalArgumentException.class)
51
+    public void writeAlphaValuesTest() throws IOException {
52
+        // given
53
+        String fileName = "file.txt";
54
+        String expected = "The quick brown foxy";
55
+        Document documentWriter = new SpecialCharDocument(fileName);
56
+
57
+        // when
58
+        documentWriter.write(expected);
59
+        String actual = documentWriter.read();
60
+
61
+        // then
62
+        Assert.assertEquals(expected, actual);
63
+    }
64
+}