public void testCercaContext() {
NativeSensorPortStub nativeSensorPortStub = new NativeSensorPortStub();
nativeSensorPortStub.setISensorPort(0, lightSensorStub);
NativeSensorPort nativeSensorPort = NativeSensorPort.getInstance();
nativeSensorPort.setBehaviour(nativeSensorPortStub);
LightSensor lightSensor = new LightSensor(SensorPort.S1);
lightSensorStub.setImage(new Image(Display.getDefault(),
"src/de/nordakademie/nxtsimulation/"
+ "test/LightSensorTestImage_white.png"));
// sollte 100%-Helligkeit sein
lightSensorStub.setPosX(50);
lightSensorStub.setPosY(50);
int brightness = lightSensor.readValue();
assertEquals(100, brightness);
lightSensorStub.setImage(new Image(Display.getDefault(),
"src/de/nordakademie/nxtsimulation/"
+ "test/LightSensorTestImage_gray.png"));
// sollte 50%-Helligkeit sein
lightSensorStub.setPosX(50);
lightSensorStub.setPosY(50);
brightness = lightSensor.readValue();
assertEquals(50, brightness, 1);
lightSensorStub.setImage(new Image(Display.getDefault(),
"src/de/nordakademie/nxtsimulation/"
+ "test/LightSensorTestImage_black.png"));
// sollte 0%-Helligkeit sein
lightSensorStub.setPosX(50);
lightSensorStub.setPosY(50);
brightness = lightSensor.readValue();
assertEquals(0, brightness);
lightSensorStub.setImage(new Image(Display.getDefault(), 10, 10));
// sollte 0%-Helligkeit sein, da Position au�erhalb des Bildes
lightSensorStub.setPosX(50);
lightSensorStub.setPosY(50);
brightness = lightSensor.readValue();
assertEquals(0, brightness);
}