Skip to content

Commit

Permalink
fixed the tests and added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nisrulz committed Feb 12, 2017
1 parent e3e33fb commit 6466209
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion sensey/src/main/java/com/github/nisrulz/sensey/Sensey.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public class Sensey {
* {@link LightListener lightListener},
* {@link OrientationListener orientationListener}
* {@link ProximityListener proximityListener}
* {@link WaveListener waveListner}
* {@link ChopListener chopListener}
* {@link MovementListener movementListner}
* {@link WristTwistListener wristTwistListner}
* and {@link ShakeListener shakeListener})
* to SensorDetectors created by those listeners.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private <T> T getDetector(Object listener, Class<T> aClass) {
public void detectListenerWithStartShakeDetectionWithCustomThreshold() {
addSensor(TYPE_ACCELEROMETER);
ShakeListener fakeListener = mock(ShakeListener.class);
sensey.startShakeDetection(4, fakeListener);
sensey.startShakeDetection(4f,1000, fakeListener);
ShakeDetector detector = getDetector(fakeListener, ShakeDetector.class);
if (detector != null) {
assertTrue("Sensor Manager must contain sensor event listener for shake",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,31 @@ public void detectShakeWithSeveralGravitySensors() {

@Test
public void detectNothingWithZeroGravityForCustomThreshold() {
testDetector(10).onSensorChanged(testAccelerometerEvent(new float[] { 0, 0, 0 }));
testDetector(10,1000).onSensorChanged(testAccelerometerEvent(new float[] { 0, 0, 0 }));
verifyNoMoreInteractions(mockListener);
}

private ShakeDetector testDetector(int threshold) {
return new ShakeDetector(threshold, mockListener);
private ShakeDetector testDetector(float threshold, long timeBeforeDeclaringShakeStopped) {
return new ShakeDetector(threshold,timeBeforeDeclaringShakeStopped, mockListener);
}

@Test
public void detectShakeWithDoubleGravityForCustomThreshold() {
testDetector(9).onSensorChanged(testAccelerometerEvent(new float[] { 0, 0, 2 * 9.81f }));
testDetector(9,1000).onSensorChanged(testAccelerometerEvent(new float[] { 0, 0, 2 * 9.81f }));
verify(mockListener, only()).onShakeDetected();
}

@Test
public void detectShakeWithSeveralGravitySensorsForCustomThreshold() {
ShakeDetector testDetector = testDetector(9);
ShakeDetector testDetector = testDetector(9,1000);
testDetector.onSensorChanged(testAccelerometerEvent(new float[] { 0, 0, 2 * 9.81f }));
testDetector.onSensorChanged(testAccelerometerEvent(new float[] { 0, 0, 2 * -9.81f }));
verify(mockListener, times(1)).onShakeDetected();
}

@Test
public void detectShakeWithSeveralStrongGravitySensorsForCustomThreshold() {
ShakeDetector testDetector = testDetector(9);
ShakeDetector testDetector = testDetector(9,1000);
testDetector.onSensorChanged(testAccelerometerEvent(new float[] { 0, 0, 2 * 9.81f }));
testDetector.onSensorChanged(testAccelerometerEvent(new float[] { 0, 0, 3 * -9.81f }));
verify(mockListener, times(2)).onShakeDetected();
Expand Down

0 comments on commit 6466209

Please sign in to comment.