Created
May 30, 2010 07:36
-
-
Save jamesshore/418861 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@RunWith(JMock.class) | |
public class _Rot13StringTest { | |
private Mockery _mockery = new JUnit4Mockery(); | |
private PersistenceMechanism _fileSystem; | |
@Before | |
public void setup() { | |
_fileSystem = _mockery.mock(PersistenceMechanism.class); | |
} | |
@Test | |
public void saveAs() throws IOException { | |
TransformableString string = new Rot13String("abc", _fileSystem); | |
_mockery.checking(new Expectations() {{ | |
oneOf (_fileSystem).overwrite("filename", "abc"); | |
}}); | |
string.saveAs("filename"); | |
} | |
@Test | |
public void writeTo() { | |
TransformableString string = new Rot13String("foo", _fileSystem); | |
final Display display = _mockery.mock(Display.class); | |
_mockery.checking(new Expectations() {{ | |
oneOf (display).write("foo"); | |
}}); | |
string.writeTo(display); | |
} |
This file contains hidden or 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
@Test | |
public void go_handlesIOExceptionNicely() throws IOException { | |
_mockery.checking(new Expectations() {{ | |
oneOf (_stringFactory).load(_inputFile); | |
will(throwException(new FileNotFoundException("file not found"))); | |
oneOf (_display).write("file not found"); | |
}}); | |
_ui.go(new String[] {_inputFile, _outputFile}); | |
} |
This file contains hidden or 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
// You might expect it to look like this: | |
public static Rot13String load(String filename) throws IOException { | |
return new Rot13String(_fileSystem.read(filename)); | |
} | |
public void saveAs(String filename) throws IOException { | |
_fileSystem.overwrite(filename, _string); | |
} |
This file contains hidden or 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
public void saveAs(String filename) throws IOException { | |
_fileSystem.overwrite(filename, _string); | |
} |
This file contains hidden or 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
// But instead it looks like this: | |
public TransformableString load(String filename) throws IOException { | |
return new Rot13String(_fileSystem.read(filename), _fileSystem); | |
} |
This file contains hidden or 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
public UI(PrintStream out, Configuration configuration) { | |
this(new ConsoleDisplay(out), new Rot13StringFileSystemLoader( | |
new FileSystem(configuration))); | |
} | |
public static void main(String[] args) { | |
main(args, System.out, Configuration.production()); | |
} | |
public static void main(String[] args, PrintStream out, Configuration configuration) { | |
new UI(out, configuration).go(args); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment