-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
src/test/java/de/taimos/gpsd4java/api/DistanceListenerTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package de.taimos.gpsd4java.api; | ||
|
||
import de.taimos.gpsd4java.types.TPVObject; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
public class DistanceListenerTest { | ||
|
||
@Test | ||
public void testDistanceListener() { | ||
|
||
final boolean[] called = new boolean[1]; | ||
|
||
final DistanceListener distanceListener = | ||
new DistanceListener(100.0) { | ||
@Override | ||
protected void handleLocation(final TPVObject tpv) { | ||
called[0] = true; | ||
} | ||
}; | ||
|
||
final TPVObject tpvObject1 = Mockito.mock(TPVObject.class); | ||
Mockito.when(tpvObject1.getLongitude()).thenReturn(1.0); | ||
Mockito.when(tpvObject1.getLatitude()).thenReturn(1.0); | ||
Mockito.when(tpvObject1.getLongitude()).thenReturn(1.0); | ||
Mockito.when(tpvObject1.getLongitude()).thenReturn(1.0); | ||
|
||
final TPVObject tpvObject2 = Mockito.mock(TPVObject.class); | ||
Mockito.when(tpvObject1.getLongitude()).thenReturn(2.0); | ||
Mockito.when(tpvObject1.getLatitude()).thenReturn(2.0); | ||
Mockito.when(tpvObject1.getLongitude()).thenReturn(2.0); | ||
Mockito.when(tpvObject1.getLongitude()).thenReturn(2.0); | ||
|
||
// first call, lastPosition is null, should call handleLocation | ||
called[0] = false; | ||
distanceListener.handleTPV(tpvObject1); | ||
Assert.assertTrue(called[0]); | ||
|
||
// second call, lastPosition is set, same position so no call | ||
called[0] = false; | ||
distanceListener.handleTPV(tpvObject1); | ||
Assert.assertFalse(called[0]); | ||
|
||
// third call, lastPosition is set, other position so should call | ||
called[0] = false; | ||
distanceListener.handleTPV(tpvObject2); | ||
Assert.assertTrue(called[0]); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/de/taimos/gpsd4java/backend/GISToolTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package de.taimos.gpsd4java.backend; | ||
|
||
import de.taimos.gpsd4java.types.TPVObject; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
public class GISToolTest { | ||
|
||
@Test | ||
public void testDistance() { | ||
|
||
// the distance between 1,1 and 2,2 is about 157 kilometers | ||
|
||
final TPVObject one = Mockito.mock(TPVObject.class); | ||
Mockito.when(one.getLongitude()).thenReturn(1.0); | ||
Mockito.when(one.getLatitude()).thenReturn(1.0); | ||
|
||
final TPVObject two = Mockito.mock(TPVObject.class); | ||
Mockito.when(two.getLongitude()).thenReturn(2.0); | ||
Mockito.when(two.getLatitude()).thenReturn(2.0); | ||
|
||
Assert.assertEquals(157.2254320380729, GISTool.getDistance(one, two), 0.0); | ||
|
||
Assert.assertEquals(0, GISTool.getDistance(one, one), 0.0); | ||
Assert.assertEquals(0, GISTool.getDistance(two, two), 0.0); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!DOCTYPE configuration> | ||
|
||
<configuration> | ||
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/> | ||
<import class="ch.qos.logback.core.ConsoleAppender"/> | ||
|
||
<appender name="STDOUT" class="ConsoleAppender"> | ||
<encoder class="PatternLayoutEncoder"> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%kvp- %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
</configuration> |