-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...d/StPatrickApp-code/src/main/java/ch/heigvd/res/stpatrick/IStreamDecoratorController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
39 changes: 39 additions & 0 deletions
39
...pp-build/StPatrickApp-tests/src/test/java/ch/heigvd/res/stpatrick/ApplicationNewTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |