Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renaming the decoders to encoders to more correctly model the problem.

  • Loading branch information...
commit 09b621266b7b44932050ea11df7957303b4cf208 1 parent ce77d68
@danielwellman authored
View
6 README
@@ -7,10 +7,10 @@ Exploring the Solution
======================
The production application entry point is good place to start: com.danielwellman.jschallenge.java1.app.Main
-All screen and file output is coordinated through a system of listeners (DecoderListener). The
+All screen and file output is coordinated through a system of listeners (EncoderListener). The
com.danielwellman.jschallenge.java1.ConverterApplication is a general-purpose implementation
-which reads an input source, decodes the message, and notifies all interested listeners that
-a message has been decoded. The Rot13-specific algorithm and Java IO listeners live in the package
+which reads an input source, encodes the message, and notifies all interested listeners that
+a message has been encoded. The Rot13-specific algorithm and Java IO listeners live in the package
com.danielwellman.jschallenge.java1.app.
I started writing this solution with an end-to-end test, com.danielwellman.jschallenge.java1.endtoend.EndToEndTest.
View
8 src/main/java/com/danielwellman/jschallenge/java1/ConverterApplication.java
@@ -5,13 +5,13 @@
public class ConverterApplication {
private final Encoder encoder;
- private final Collection<DecoderListener> listeners = new ArrayList<DecoderListener>();
+ private final Collection<EncoderListener> listeners = new ArrayList<EncoderListener>();
public ConverterApplication(Encoder encoder) {
this.encoder = encoder;
}
- public void addListener(DecoderListener listener) {
+ public void addListener(EncoderListener listener) {
listeners.add(listener);
}
@@ -19,8 +19,8 @@ public void convert(InputReader inputFile) {
final String contents = inputFile.read();
final String encoded = encoder.encode(contents);
- for (DecoderListener listener : listeners) {
- listener.messageDecoded(encoded);
+ for (EncoderListener listener : listeners) {
+ listener.messageEncoded(encoded);
}
}
}
View
5 src/main/java/com/danielwellman/jschallenge/java1/DecoderListener.java
@@ -1,5 +0,0 @@
-package com.danielwellman.jschallenge.java1;
-
-public interface DecoderListener {
- void messageDecoded(String message);
-}
View
5 src/main/java/com/danielwellman/jschallenge/java1/EncoderListener.java
@@ -0,0 +1,5 @@
+package com.danielwellman.jschallenge.java1;
+
+public interface EncoderListener {
+ void messageEncoded(String message);
+}
View
16 src/main/java/com/danielwellman/jschallenge/java1/app/ConsoleAppendingDecoderListener.java
@@ -1,16 +0,0 @@
-package com.danielwellman.jschallenge.java1.app;
-
-import com.danielwellman.jschallenge.java1.DecoderListener;
-import com.danielwellman.jschallenge.java1.OutputWriter;
-
-public class ConsoleAppendingDecoderListener implements DecoderListener {
- private final OutputWriter out;
-
- public ConsoleAppendingDecoderListener(OutputWriter out) {
- this.out = out;
- }
-
- public void messageDecoded(String message) {
- out.println(message);
- }
-}
View
16 src/main/java/com/danielwellman/jschallenge/java1/app/ConsoleAppendingEncoderListener.java
@@ -0,0 +1,16 @@
+package com.danielwellman.jschallenge.java1.app;
+
+import com.danielwellman.jschallenge.java1.EncoderListener;
+import com.danielwellman.jschallenge.java1.OutputWriter;
+
+public class ConsoleAppendingEncoderListener implements EncoderListener {
+ private final OutputWriter out;
+
+ public ConsoleAppendingEncoderListener(OutputWriter out) {
+ this.out = out;
+ }
+
+ public void messageEncoded(String message) {
+ out.println(message);
+ }
+}
View
16 src/main/java/com/danielwellman/jschallenge/java1/app/FileAppenderDecoderListener.java
@@ -1,16 +0,0 @@
-package com.danielwellman.jschallenge.java1.app;
-
-import com.danielwellman.jschallenge.java1.DecoderListener;
-import com.danielwellman.jschallenge.java1.OutputWriter;
-
-public class FileAppenderDecoderListener implements DecoderListener {
- private final OutputWriter file;
-
- public FileAppenderDecoderListener(OutputWriter file) {
- this.file = file;
- }
-
- public void messageDecoded(String message) {
- file.println(message);
- }
-}
View
16 src/main/java/com/danielwellman/jschallenge/java1/app/FileAppenderEncoderListener.java
@@ -0,0 +1,16 @@
+package com.danielwellman.jschallenge.java1.app;
+
+import com.danielwellman.jschallenge.java1.EncoderListener;
+import com.danielwellman.jschallenge.java1.OutputWriter;
+
+public class FileAppenderEncoderListener implements EncoderListener {
+ private final OutputWriter file;
+
+ public FileAppenderEncoderListener(OutputWriter file) {
+ this.file = file;
+ }
+
+ public void messageEncoded(String message) {
+ file.println(message);
+ }
+}
View
4 src/main/java/com/danielwellman/jschallenge/java1/app/Main.java
@@ -21,8 +21,8 @@ public Main(FileSystemFacade fileSystemFacade, Encoder encoder, OutputWriter out
public void run(String inputFilename, String outputFilename) {
final ConverterApplication converter = new ConverterApplication(encoder);
- converter.addListener(new ConsoleAppendingDecoderListener(output));
- converter.addListener(new FileAppenderDecoderListener(fileSystemFacade.createFile(outputFilename)));
+ converter.addListener(new ConsoleAppendingEncoderListener(output));
+ converter.addListener(new FileAppenderEncoderListener(fileSystemFacade.createFile(outputFilename)));
converter.convert(fileSystemFacade.openFileForRead(inputFilename));
}
View
10 ...va1/unit/ConsoleAppendingDecoderListenerTest.java → ...va1/unit/ConsoleAppendingEncoderListenerTest.java
@@ -1,8 +1,8 @@
package com.danielwellman.jschallenge.java1.unit;
-import com.danielwellman.jschallenge.java1.DecoderListener;
+import com.danielwellman.jschallenge.java1.EncoderListener;
import com.danielwellman.jschallenge.java1.OutputWriter;
-import com.danielwellman.jschallenge.java1.app.ConsoleAppendingDecoderListener;
+import com.danielwellman.jschallenge.java1.app.ConsoleAppendingEncoderListener;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
@@ -10,7 +10,7 @@
import org.junit.runner.RunWith;
@RunWith(JMock.class)
-public class ConsoleAppendingDecoderListenerTest {
+public class ConsoleAppendingEncoderListenerTest {
private final Mockery context = new Mockery();
private final OutputWriter out = context.mock(OutputWriter.class);
@@ -21,8 +21,8 @@ public void writesMessageToTheOutputStream() {
oneOf(out).println("Hello, world!");
}});
- final DecoderListener listener = new ConsoleAppendingDecoderListener(out);
+ final EncoderListener listener = new ConsoleAppendingEncoderListener(out);
- listener.messageDecoded("Hello, world!");
+ listener.messageEncoded("Hello, world!");
}
}
View
10 src/test/java/com/danielwellman/jschallenge/java1/unit/ConverterApplicationTest.java
@@ -1,8 +1,8 @@
package com.danielwellman.jschallenge.java1.unit;
import com.danielwellman.jschallenge.java1.ConverterApplication;
-import com.danielwellman.jschallenge.java1.DecoderListener;
import com.danielwellman.jschallenge.java1.Encoder;
+import com.danielwellman.jschallenge.java1.EncoderListener;
import com.danielwellman.jschallenge.java1.InputReader;
import org.jmock.Expectations;
import org.jmock.Mockery;
@@ -31,15 +31,15 @@ public void readsTheFileAndAsksEncoderToEncodeItsContents() {
}
@Test
- public void notifiesTheListenersWhenAFileIsDecoded() {
- final DecoderListener listener = context.mock(DecoderListener.class);
- final String message = "decoded message";
+ public void notifiesTheListenersWhenAFileIsEncoded() {
+ final EncoderListener listener = context.mock(EncoderListener.class);
+ final String message = "encoded message";
context.checking(new Expectations() {{
ignoring(inputFile);
allowing(encoder).encode(with(any(String.class))); will(returnValue(message));
- oneOf(listener).messageDecoded(message);
+ oneOf(listener).messageEncoded(message);
}});
converter.addListener(listener);
View
10 ...e/java1/unit/FileAppenderDecoderListenerTest.java → ...e/java1/unit/FileAppenderEncoderListenerTest.java
@@ -1,8 +1,8 @@
package com.danielwellman.jschallenge.java1.unit;
-import com.danielwellman.jschallenge.java1.DecoderListener;
+import com.danielwellman.jschallenge.java1.EncoderListener;
import com.danielwellman.jschallenge.java1.OutputWriter;
-import com.danielwellman.jschallenge.java1.app.FileAppenderDecoderListener;
+import com.danielwellman.jschallenge.java1.app.FileAppenderEncoderListener;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
@@ -11,7 +11,7 @@
@RunWith(JMock.class)
-public class FileAppenderDecoderListenerTest {
+public class FileAppenderEncoderListenerTest {
private final Mockery context = new Mockery();
private final OutputWriter file = context.mock(OutputWriter.class);
@@ -23,7 +23,7 @@ public void testSavesTheMessageToAFile() {
oneOf(file).println(message);
}});
- final DecoderListener listener = new FileAppenderDecoderListener(file);
- listener.messageDecoded(message);
+ final EncoderListener listener = new FileAppenderEncoderListener(file);
+ listener.messageEncoded(message);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.