Created
July 30, 2015 17:18
-
-
Save nicopaez/0d567fc832725f03c143 to your computer and use it in GitHub Desktop.
ejercicio_mocking
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 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