Skip to content

Instantly share code, notes, and snippets.

@greghelton
Created December 26, 2011 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greghelton/1522045 to your computer and use it in GitHub Desktop.
Save greghelton/1522045 to your computer and use it in GitHub Desktop.
Java: Dumb class only to demonstrate Mockito (see unit test)
package us.home.electronics;
import java.io.Console;
import java.io.IOException;
/**
* For conciseness, throw classes into just one source file
*/
public interface Programmable {
public void programDevice(Programmable.ProgramCoder coder)
throws IOException;
public String execute();
public String getCode();
/*
* programmable device
*/
public class AlarmClock implements Programmable {
String code;
@Override
public void programDevice(Programmable.ProgramCoder coder)
throws IOException {
this.code = coder.getProgramCode();
}
@Override
public String execute() {
return code;
}
@Override
public String getCode() {
return code;
}
}
/*
* helper class to accept console input
*/
public class ProgramCoder {
public String getProgramCode() throws IOException {
String code;
System.out.print("Enter the code please: ");
Console console = System.console();
code = console.readLine();
return code;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment