reorganize tests

This commit is contained in:
Minecon724 2024-05-31 13:02:25 +02:00
parent 70a1da8c8c
commit 97473c4aae
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
7 changed files with 118 additions and 9 deletions

View file

@ -1,4 +1,4 @@
package eu.m724.wtapi;
package eu.m724.wtapi.object;
import org.junit.Test;

View file

@ -1,4 +1,4 @@
package eu.m724.wtapi;
package eu.m724.wtapi.thunder;
import java.util.ArrayList;
@ -8,7 +8,7 @@ import eu.m724.wtapi.object.Coordinates;
import eu.m724.wtapi.thunder.ThunderProvider;
import eu.m724.wtapi.thunder.impl.lightningmaps.LightningMapsProvider;
public class TestLM {
public class LightningMapsTest {
@Test
public void lightningMapsTest() throws InterruptedException {
ArrayList<Coordinates> coordinatesList = new ArrayList<>();
@ -28,6 +28,7 @@ public class TestLM {
}
System.out.printf("Strikes in the last 10s: %d\n", coordinatesList.size());
if (coordinatesList.size() > 0) // lightningmaps can be unreliable
System.out.printf("%f %f", coordinatesList.get(0).latitude, coordinatesList.get(0).longitude);
}

View file

@ -0,0 +1,73 @@
package eu.m724.wtapi.thunder;
import java.util.ArrayList;
import java.util.Random;
import java.util.function.Consumer;
import eu.m724.wtapi.object.Coordinates;
import eu.m724.wtapi.provider.exception.ProviderException;
import eu.m724.wtapi.thunder.ThunderProvider;
import eu.m724.wtapi.thunder.impl.lightningmaps.TimedStrike;
public class MockThunderProvider extends ThunderProvider {
ArrayList<Consumer<Coordinates>> strikeHandlers = new ArrayList<>();
ArrayList<TimedStrike> strikes = new ArrayList<>();
Random rnd = new Random();
@Override
public void init() throws ProviderException {
System.out.println("mock thunder init");
}
@Override
public void start() throws ProviderException {
System.out.println("mock thunder start");
long now = System.currentTimeMillis();
for (int i=0; i<40; i++) {
strikes.add(new TimedStrike(now + i * 100,
new Coordinates(
rnd.nextDouble(-90, 90),
rnd.nextDouble(-180, 180)
)));
}
}
@Override
public void stop() {
System.out.println("mock thunder stop");
}
@Override
public void tick() {
long now = System.currentTimeMillis();
while (strikes.size() > 0) {
TimedStrike str = strikes.get(0);
if (now > str.timestamp) {
System.out.printf("mock thunder given: %d\n", str.timestamp);
strikeHandlers.forEach(con -> con.accept(str.coordinates));
strikes.remove(0);
} else break;
}
System.out.println("mock thunder tick");
}
@Override
public void registerStrikeHandler(Consumer<Coordinates> runnable) {
strikeHandlers.add(runnable);
System.out.println("mock thunder strike handler added");
}
@Override
public int getDelay() {
// TODO Auto-generated method stub
return 10000;
}
}

View file

@ -0,0 +1,36 @@
package eu.m724.wtapi.thunder;
import java.util.ArrayList;
import org.junit.Test;
import eu.m724.wtapi.object.Coordinates;
import eu.m724.wtapi.thunder.ThunderProvider;
public class ThunderProviderTest {
@Test
public void testThunderProvider() throws InterruptedException {
ArrayList<Coordinates> coordinatesList = new ArrayList<>();
ThunderProvider provider = new MockThunderProvider();
provider.registerStrikeHandler(coordinates ->
coordinatesList.add(coordinates));
provider.init();
provider.start();
for (int i=0; i < 50; i++) {
provider.tick();
Thread.sleep(50);
}
provider.stop();
System.out.printf("Strikes in the last 5s: %d\n", coordinatesList.size());
System.out.printf("%f %f", coordinatesList.get(0).latitude, coordinatesList.get(0).longitude);
assert coordinatesList.size() == 25;
}
}

View file

@ -1,4 +1,4 @@
package eu.m724.wtapi.impl;
package eu.m724.wtapi.weather;
import java.util.concurrent.CompletableFuture;
import eu.m724.wtapi.object.Coordinates;

View file

@ -1,4 +1,4 @@
package eu.m724.wtapi;
package eu.m724.wtapi.weather;
import static org.junit.Assert.assertNotNull;
@ -12,7 +12,7 @@ import eu.m724.wtapi.object.Weather;
import eu.m724.wtapi.provider.WeatherProvider;
import eu.m724.wtapi.provider.impl.openweathermap.OpenWeatherMapProvider;
public class TestOWM {
public class OpenWeatherMapTest {
@Test
public void openWeatherMapTest() throws InterruptedException, ExecutionException {
String apiKey = "f3198d2a4ae3076e0aa47c821a253447";

View file

@ -1,4 +1,4 @@
package eu.m724.wtapi;
package eu.m724.wtapi.weather;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@ -10,7 +10,6 @@ import java.util.concurrent.ExecutionException;
import org.junit.Test;
import eu.m724.wtapi.impl.MockWeatherProvider;
import eu.m724.wtapi.object.Coordinates;
import eu.m724.wtapi.object.Weather;
import eu.m724.wtapi.provider.WeatherProvider;