Skip to content

Commit

Permalink
New specs have been added
Browse files Browse the repository at this point in the history
  • Loading branch information
wasadigi committed Mar 20, 2017
1 parent a048a86 commit 448a156
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ public IStreamProcessorsFactory getStreamProcessorsFactory() {
return processorsFactory;
}

IStreamDecoratorController getStreamDecoratorController() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

}

0 comments on commit 448a156

Please sign in to comment.