Search in sources :

Example 1 with Bus

use of cl.smartcities.isci.transportinspector.backend.Bus in project androidApp by InspectorIncognito.

the class DetectionServiceTest method testManualGetOutOfBus.

@Test
public void testManualGetOutOfBus() throws TimeoutException {
    DetectionService spyService = spy(service);
    BusStop mockBusStop = mock(BusStop.class);
    when(mockBusStop.getIncomingBuses()).thenReturn(new ArrayList<Bus>());
    Bus bus = new Bus("506", "GGWP00", "");
    spyService.setCurrentState(new VehicleState(new IdleState(spyService), bus, mock(StateLocationSender.class)));
    spyService.onBusDetected(bus);
    assertTrue(spyService.isRunningInForeground());
    spyService.outOfBus();
    assertFalse(spyService.isRunningInForeground());
}
Also used : Bus(cl.smartcities.isci.transportinspector.backend.Bus) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Test(org.junit.Test)

Example 2 with Bus

use of cl.smartcities.isci.transportinspector.backend.Bus in project androidApp by InspectorIncognito.

the class DetectionServiceTest method testGetOutOfBus.

@Test
public void testGetOutOfBus() throws TimeoutException {
    DetectionService spyService = spy(service);
    BusStop mockBusStop = mock(BusStop.class);
    when(mockBusStop.getIncomingBuses()).thenReturn(new ArrayList<Bus>());
    Bus bus = new Bus("506", "GGWP00", "");
    spyService.setCurrentState(new VehicleState(new IdleState(spyService), bus, mock(StateLocationSender.class)));
    spyService.onBusDetected(bus);
    assertTrue(spyService.isRunningInForeground());
    spyService.onActivityChanged(new DetectedActivity(DetectedActivity.WALKING, 100));
    spyService.onActivityChanged(new DetectedActivity(DetectedActivity.IN_VEHICLE, 100));
    spyService.onActivityChanged(new DetectedActivity(DetectedActivity.WALKING, 100));
    spyService.fakeOnTimePassed();
    assertFalse(spyService.isRunningInForeground());
}
Also used : Bus(cl.smartcities.isci.transportinspector.backend.Bus) DetectedActivity(com.google.android.gms.location.DetectedActivity) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Test(org.junit.Test)

Example 3 with Bus

use of cl.smartcities.isci.transportinspector.backend.Bus in project androidApp by InspectorIncognito.

the class DetectionServiceTest method testBusDetectedNotificationIsSent.

@Test
public void testBusDetectedNotificationIsSent() throws TimeoutException {
    DetectionService spyService = spy(service);
    BusStop mockBusStop = mock(BusStop.class);
    when(mockBusStop.getIncomingBuses()).thenReturn(new ArrayList<Bus>());
    // IdleState is set
    spyService.setCurrentState(new IdleState(spyService));
    // BusStop is selected
    spyService.busStopSelected(mockBusStop);
    // New IN_VEHICLE Detected Activity
    spyService.onActivityChanged(new DetectedActivity(DetectedActivity.IN_VEHICLE, 100));
// TODO(aantoine): REDO this test
// verify(spyService).sendNotification(anyInt(), any(NotificationCompat.Builder.class));
}
Also used : Bus(cl.smartcities.isci.transportinspector.backend.Bus) DetectedActivity(com.google.android.gms.location.DetectedActivity) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Test(org.junit.Test)

Example 4 with Bus

use of cl.smartcities.isci.transportinspector.backend.Bus in project androidApp by InspectorIncognito.

the class BusSelectionAdapterTest method setUp.

@Before
public void setUp() throws Exception {
    listener = mock(BusSelectionAdapter.ListViewAdapterListener.class);
    HashMap<String, ArrayList<Bus>> busHashMap = new HashMap<>();
    ArrayList<Bus> array509 = new ArrayList<>();
    array509.add(new Bus("509", "GGWP10", ""));
    array509.add(new Bus("509", "GGWP11", ""));
    busHashMap.put("509", array509);
    ArrayList<Bus> array506 = new ArrayList<>();
    array506.add(new Bus("506", "GGWP20", ""));
    array506.add(new Bus("506", "GGWP21", ""));
    busHashMap.put("506", array506);
    ArrayList<Bus> array507 = new ArrayList<>();
    b507first = new Bus("507", "GGWP00", "");
    b507second = new Bus("507", "GGWP01", "");
    array507.add(b507first);
    array507.add(b507second);
    busHashMap.put("507", array507);
    ArrayList<Bus> array506v = new ArrayList<>();
    b506first = new Bus("506v", "GGWP03", "");
    array506v.add(b506first);
    busHashMap.put("506v", array506v);
    ArrayList<String> serviceList = new ArrayList<>();
    serviceList.add("509");
    serviceList.add("506");
    serviceList.add("507");
    serviceList.add("506v");
    mAdapter = new BusSelectionAdapter(rule.getActivity(), serviceList, busHashMap, listener);
}
Also used : Bus(cl.smartcities.isci.transportinspector.backend.Bus) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BusSelectionAdapter(cl.smartcities.isci.transportinspector.adapters.dialogAdapters.BusSelectionAdapter) Before(org.junit.Before)

Example 5 with Bus

use of cl.smartcities.isci.transportinspector.backend.Bus in project androidApp by InspectorIncognito.

the class DetectionServiceTest method testRegisterUnregister.

@Test
public void testRegisterUnregister() throws TimeoutException {
    Bus mockBus = mock(Bus.class);
    DetectionService.ServiceListener mockListener = mock(DetectionService.ServiceListener.class);
    service.register(mockListener);
    service.onBusDetected(mockBus);
    assertEquals(mockBus, service.getCurrentBus());
    assertTrue(service.isRunningInForeground());
    verify(mockListener, times(1)).nowOnForeground(mockBus);
    service.outOfBus();
    assertNull(service.getCurrentBus());
    assertFalse(service.isRunningInForeground());
    verify(mockListener, times(1)).nowOnForeground(mockBus);
    service.unregister(mockListener);
    service.onBusDetected(mockBus);
    verify(mockListener, times(1)).nowOnForeground(mockBus);
}
Also used : Bus(cl.smartcities.isci.transportinspector.backend.Bus) Test(org.junit.Test)

Aggregations

Bus (cl.smartcities.isci.transportinspector.backend.Bus)6 Test (org.junit.Test)4 BusStop (cl.smartcities.isci.transportinspector.backend.BusStop)3 DetectedActivity (com.google.android.gms.location.DetectedActivity)2 NotificationManager (android.app.NotificationManager)1 Bundle (android.os.Bundle)1 BusSelectionAdapter (cl.smartcities.isci.transportinspector.adapters.dialogAdapters.BusSelectionAdapter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1