コード例 #1
0
  @Test
  public void shouldReturnNullLocationWhenACriteriaFailsAndNoBestExists() {
    addCriteria(failsCriteria);

    Location location = bestLocationDelegate.getBestLastKnownLocation();
    assertNull(location);
    assertNotSame(location, candidateLocation);
  }
コード例 #2
0
  @Test
  public void shouldReturnCandidateLocationWhenAllCriteriaPass() {
    addCriteria(passesCriteria);

    mockAccurateLocation(locationManager);
    Location location = bestLocationDelegate.getBestLastKnownLocation();
    assertSame(location, candidateLocation);
  }
コード例 #3
0
  @Test
  public void shouldReturnPreviousGoodLocationIfACriteriaFailsForCandidate() {
    LocationCriteria failsForCandidateCriteria = mock(LocationCriteria.class);

    mockLessAccurateLocation(locationManager);
    mockAccurateLocation(locationManager);

    addCriteria(failsForCandidateCriteria);

    when(failsForCandidateCriteria.passes(eq(previousLocation), any(Location.class)))
        .thenReturn(true);
    when(failsForCandidateCriteria.passes(candidateLocation, previousLocation)).thenReturn(false);

    Location bestLastKnownLocation = bestLocationDelegate.getBestLastKnownLocation();

    assertSame(previousLocation, bestLastKnownLocation);
  }