Created
December 26, 2011 20:24
-
-
Save greghelton/1522045 to your computer and use it in GitHub Desktop.
Java: Dumb class only to demonstrate Mockito (see unit test)
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
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