diff --git a/StPatrickApp-build/StPatrickApp-code/src/main/java/ch/heigvd/res/stpatrick/Application.java b/StPatrickApp-build/StPatrickApp-code/src/main/java/ch/heigvd/res/stpatrick/Application.java index 282c7e6..57c6f0f 100644 --- a/StPatrickApp-build/StPatrickApp-code/src/main/java/ch/heigvd/res/stpatrick/Application.java +++ b/StPatrickApp-build/StPatrickApp-code/src/main/java/ch/heigvd/res/stpatrick/Application.java @@ -13,4 +13,7 @@ public IStreamProcessorsFactory getStreamProcessorsFactory() { return processorsFactory; } + IStreamDecoratorController getStreamDecoratorController() { + return null; + } } diff --git a/StPatrickApp-build/StPatrickApp-code/src/main/java/ch/heigvd/res/stpatrick/IStreamDecoratorController.java b/StPatrickApp-build/StPatrickApp-code/src/main/java/ch/heigvd/res/stpatrick/IStreamDecoratorController.java new file mode 100644 index 0000000..ecc1ca3 --- /dev/null +++ b/StPatrickApp-build/StPatrickApp-code/src/main/java/ch/heigvd/res/stpatrick/IStreamDecoratorController.java @@ -0,0 +1,33 @@ +package ch.heigvd.res.stpatrick; + +import java.io.Reader; +import java.io.Writer; + +/** + * A class that implements this interface has the responsibility to "decorate" a + * reader and a writer (to add some sort of functionality to them). + * + * @author Olivier Liechti + */ +public interface IStreamDecoratorController { + + /** + * The client calls this method to ask the class to decorate an existing + * reader. In other words, the client tells "I have this reader, please add + * some functionality to it". + * + * @param inputReader the existing reader + * @return the decorated reader + */ + Reader decorateReader(Reader inputReader); + + /** + * The client calls this method to ask the class to decorate an existing + * writer. In other words, the client tells "I have this writer, please add + * some functionality to it". + * + * @param outputWriter the existing writer + * @return the decorated writer + */ + Writer decorateWriter(Writer outputWriter); +} diff --git a/StPatrickApp-build/StPatrickApp-tests/src/test/java/ch/heigvd/res/stpatrick/ApplicationNewTest.java b/StPatrickApp-build/StPatrickApp-tests/src/test/java/ch/heigvd/res/stpatrick/ApplicationNewTest.java new file mode 100644 index 0000000..6884c27 --- /dev/null +++ b/StPatrickApp-build/StPatrickApp-tests/src/test/java/ch/heigvd/res/stpatrick/ApplicationNewTest.java @@ -0,0 +1,39 @@ +package ch.heigvd.res.stpatrick; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +/** + * + * @author Olivier Liechti + */ +public class ApplicationNewTest { + + String input = "We are going to have an unbelievable, perhaps record-setting turnout for the inauguration, and there will be plenty of movie and entertainment stars. All the dress shops are sold out in Washington. It’s hard to find a great dress for this inauguration."; + + @Test + public void itShouldBePossibleToGetRemoveCharacterAFromAStream() throws IOException { + Application application = new Application(); + IStreamProcessorsFactory factory = application.getStreamProcessorsFactory(); + IStreamProcessor processor = factory.getProcessor(); + StringReader inputReader = new StringReader(input); + StringWriter outputWriter = new StringWriter(); + IStreamDecoratorController controller = application.getStreamDecoratorController(); + Reader decoratedReader = controller.decorateReader(inputReader); + Writer decoratedWriter = controller.decorateWriter(outputWriter); + try { + processor.process(decoratedReader, decoratedWriter); + String output = outputWriter.toString(); + assertEquals(-1, output.indexOf('a')); + assertEquals(-1, output.indexOf('A')); + } catch (IOException e) { + throw e; + } + } + +}