package cgeo.geocaching.sensors;

import static org.assertj.core.api.Assertions.assertThat;

import cgeo.geocaching.MainActivity;
import cgeo.geocaching.utils.AngleUtils;

import android.test.ActivityInstrumentationTestCase2;

public class SensorsTest extends ActivityInstrumentationTestCase2<MainActivity> {

    public SensorsTest() {
        super(MainActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    public static void testGetDirectionNow() {
        final float angle = AngleUtils.getDirectionNow(1.0f);
        assertThat(angle == 1.0f || angle == 91.0f || angle == 181.0f || angle == 271.0f).isTrue();
    }

}

@@ -161,24 +161,47 @@
 ngleUtils;%0A%0A
+import rx.Observable;%0A%0A
 import andro
@@ -243,16 +243,55 @@
 Case2;%0A%0A
+import java.util.concurrent.TimeUnit;%0A%0A
 public c
@@ -365,16 +365,46 @@
 ity%3E %7B%0A%0A
+    private Sensors sensors;%0A%0A
     publ
@@ -543,24 +543,65 @@
 er.setUp();%0A
+        sensors = Sensors.getInstance();%0A
     %7D%0A%0A    p
@@ -704,16 +704,16 @@
 (1.0f);%0A
-
         
@@ -811,10 +811,605 @@
 %0A    %7D%0A%0A
+    private static %3CT%3E void testDataAvailability(final Observable%3CT%3E observable) %7B%0A        try %7B%0A            observable.timeout(200, TimeUnit.MILLISECONDS).first().toBlocking().single();%0A        %7D catch (final Exception ignored) %7B%0A            fail(%22timeout while waiting for sensor data%22);%0A        %7D%0A    %7D%0A%0A    public void testDirectionObservable() %7B%0A        testDataAvailability(sensors.directionObservable());%0A    %7D%0A%0A    public void testGeodataObservable() %7B%0A        testDataAvailability(sensors.geoDataObservable(false));%0A        testDataAvailability(sensors.geoDataObservable(true));%0A    %7D%0A%0A
 %7D%0A

Check that a position and an orientation are always immediately available