コード例 #1
0
  @Test
  public void testCreate() {
    GeocacheFactory geocacheFactory = PowerMock.createMock(GeocacheFactory.class);
    SharedPreferences preferences = PowerMock.createMock(SharedPreferences.class);
    Geocache geocache = PowerMock.createMock(Geocache.class);

    EasyMock.expect(preferences.getString(Geocache.ID, "GCMEY7")).andReturn("GC123");
    EasyMock.expect(preferences.getString(Geocache.NAME, "Google Falls")).andReturn("a cache");
    EasyMock.expect(preferences.getFloat(Geocache.LATITUDE, 0)).andReturn(37f);
    EasyMock.expect(preferences.getFloat(Geocache.LONGITUDE, 0)).andReturn(-122f);
    EasyMock.expect(preferences.getInt(Geocache.SOURCE_TYPE, -1))
        .andReturn(Source.MY_LOCATION.toInt());
    EasyMock.expect(geocacheFactory.sourceFromInt(Source.MY_LOCATION.toInt()))
        .andReturn(Source.MY_LOCATION);
    EasyMock.expect(preferences.getString(Geocache.SOURCE_NAME, "")).andReturn(null);
    EasyMock.expect(preferences.getInt(Geocache.CACHE_TYPE, 0)).andReturn(1);
    EasyMock.expect(geocacheFactory.cacheTypeFromInt(1)).andReturn(CacheType.TRADITIONAL);
    EasyMock.expect(preferences.getInt(Geocache.DIFFICULTY, 0)).andReturn(2);
    EasyMock.expect(preferences.getInt(Geocache.CONTAINER, 0)).andReturn(3);
    EasyMock.expect(preferences.getInt(Geocache.TERRAIN, 0)).andReturn(4);
    EasyMock.expect(preferences.getBoolean("available", true)).andReturn(true);
    EasyMock.expect(preferences.getBoolean("archived", false)).andReturn(false);
    EasyMock.expect(
            geocacheFactory.create(
                "GC123",
                "a cache",
                37f,
                -122f,
                Source.MY_LOCATION,
                null,
                CacheType.TRADITIONAL,
                2,
                4,
                3,
                true,
                false))
        .andReturn(geocache);

    PowerMock.replayAll();
    GeocacheFromPreferencesFactory geocacheFromPreferencesFactory =
        new GeocacheFromPreferencesFactory(geocacheFactory);
    assertEquals(geocache, geocacheFromPreferencesFactory.create(preferences));
    PowerMock.verifyAll();
  }
コード例 #2
0
  @Test
  public void testCreate() {
    LocationControlBuffered locationControlBuffered =
        PowerMock.createMock(LocationControlBuffered.class);
    Location location = PowerMock.createMock(Location.class);
    GeocacheFactory geocacheFactory = PowerMock.createMock(GeocacheFactory.class);
    Geocache geocache = PowerMock.createMock(Geocache.class);
    Locale.setDefault(Locale.ENGLISH);
    TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));

    EasyMock.expect(locationControlBuffered.getLocation()).andReturn(location);
    EasyMock.expect(location.getTime()).andReturn(1000000L);
    EasyMock.expect(location.getLatitude()).andReturn(37.0);
    EasyMock.expect(location.getLongitude()).andReturn(-122.0);
    EasyMock.expect(
            geocacheFactory.create(
                "ML161640",
                "[16:16] My Location",
                37.0,
                -122.0,
                Source.MY_LOCATION,
                null,
                CacheType.MY_LOCATION,
                0,
                0,
                0,
                true,
                false))
        .andReturn(geocache);

    PowerMock.replayAll();
    assertEquals(
        geocache,
        new GeocacheFromMyLocationFactory(geocacheFactory, locationControlBuffered).create());
    PowerMock.verifyAll();
  }