Skip to content

Instantly share code, notes, and snippets.

@nicopaez
Created July 30, 2015 17:18
Show Gist options
  • Save nicopaez/0d567fc832725f03c143 to your computer and use it in GitHub Desktop.
Save nicopaez/0d567fc832725f03c143 to your computer and use it in GitHub Desktop.
ejercicio_mocking
public class Robot {
private Direction direccion;
private Sensor sensor;
public Robot(Sensor sensor) {
this.sensor = sensor;
}
public void setDirection(Direction direccion) {
this.direccion = direccion;
}
public void move() {
if (this.sensor.isInContact()) {
this.direccion = this.direccion.getInverse();
}
}
public Direction getDirection() {
return this.direccion;
}
}
public class Direction {
private static Direction north;
private static Direction south;
private static Direction east;
private static Direction west;
static {
north = new Direction();
south = new Direction();
east = new Direction();
west = new Direction();
north.setInverse(south);
south.setInverse(north);
east.setInverse(west);
west.setInverse(east);
}
private Direction inverse;
private Direction() {}
private void setInverse(Direction inverse) {
this.inverse = inverse;
}
public static Direction north() {
return north;
}
public Direction getInverse() {
return this.inverse;
}
}
public interface Sensor {
boolean isInContact();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment