@Test
    @SuppressWarnings("PMD.ExcessiveMethodLength")
    public void testMergeInventory() {
        final Geocache cache = new Geocache();

        final List<Trackable> inventory1 = new ArrayList<>(4);

        // TB to be cleared
        final Trackable trackable1 = new Trackable();
        trackable1.setGeocode("TB1234");
        trackable1.setName("TB 1234");
        trackable1.setTrackingcode("TRACK 1");
        trackable1.forceSetBrand(TrackableBrand.TRAVELBUG);
        inventory1.add(trackable1);

        // TB to be updated
        final Trackable trackable2 = new Trackable();
        trackable2.setGeocode("GK1234"); // must be kept intact
        trackable2.setName("GK 1234 OLD NAME"); // must be overridden
        trackable2.setDistance(100F); // must be overridden
        trackable2.setTrackingcode("TRACK 2"); // must be kept intact
        trackable2.forceSetBrand(TrackableBrand.GEOKRETY);
        inventory1.add(trackable2);

        // TB to be removed
        final Trackable trackable3 = new Trackable();
        trackable3.setGeocode("GK6666");
        trackable3.forceSetBrand(TrackableBrand.GEOKRETY);
        inventory1.add(trackable3);

        // TB to be untouched
        final Trackable trackable4 = new Trackable();
        trackable4.setGeocode("UN0000");
        trackable4.forceSetBrand(TrackableBrand.UNKNOWN);
        inventory1.add(trackable4);

        cache.setInventory(inventory1);
        assertThat(cache.getInventory()).hasSize(4);
        assertThat(cache.getInventoryItems()).isEqualTo(4);

        final EnumSet<TrackableBrand> processedBrands = EnumSet.noneOf(TrackableBrand.class);
        processedBrands.add(TrackableBrand.GEOKRETY);
        // This brand must be cleared from result as it don't appear in "inventory2"
        processedBrands.add(TrackableBrand.TRAVELBUG);
        //deliberatly not declare TrackableBrand.UNKNOWN. They must not be removed from merge result

        final List<Trackable> inventory2 = new ArrayList<>(3);

        // new TB
        final Trackable trackable5 = new Trackable();
        trackable5.setGeocode("SW1234");
        trackable5.setName("SW 1234");
        trackable5.setDistance(100F);
        trackable5.forceSetBrand(TrackableBrand.UNKNOWN);
        inventory2.add(trackable5);

        // TB updater
        final Trackable trackable6 = new Trackable();
        trackable6.setGeocode("GK1234");
        trackable2.setName("GK 1234 _NEW_ NAME");
        trackable6.setDistance(200F);
        trackable6.forceSetBrand(TrackableBrand.GEOKRETY);
        inventory2.add(trackable6);

        // new TB
        final Trackable trackable7 = new Trackable();
        trackable7.setGeocode("GK4321");
        trackable7.setName("GK 4321");
        trackable7.setDistance(300F);
        trackable7.forceSetBrand(TrackableBrand.GEOKRETY);
        inventory2.add(trackable7);

        cache.mergeInventory(inventory2, processedBrands);

        assertThat(cache.getInventory()).hasSize(4);
        assertThat(cache.getInventoryItems()).isEqualTo(4);

        assertThat(cache.getInventory().get(0)).isEqualTo(trackable5);
        assertThat(cache.getInventory().get(0).getGeocode()).isEqualTo("SW1234");
        assertThat(cache.getInventory().get(0).getName()).isEqualTo("SW 1234");
        assertThat(cache.getInventory().get(0).getDistance()).isEqualTo(100F);
        assertThat(cache.getInventory().get(0).getOwner()).isNull();
        assertThat(cache.getInventory().get(0).getBrand()).isEqualTo(TrackableBrand.UNKNOWN);

        assertThat(cache.getInventory().get(1)).isEqualTo(trackable2);
        assertThat(cache.getInventory().get(1).getGeocode()).isEqualTo("GK1234");
        assertThat(cache.getInventory().get(1).getName()).isEqualTo("GK 1234 _NEW_ NAME");
        assertThat(cache.getInventory().get(1).getDistance()).isEqualTo(200F);
        assertThat(cache.getInventory().get(1).getTrackingcode()).isEqualTo("TRACK 2");
        assertThat(cache.getInventory().get(1).getOwner()).isNull();
        assertThat(cache.getInventory().get(1).getBrand()).isEqualTo(TrackableBrand.GEOKRETY);

        assertThat(cache.getInventory().get(2)).isEqualTo(trackable7);
        assertThat(cache.getInventory().get(2).getGeocode()).isEqualTo("GK4321");
        assertThat(cache.getInventory().get(2).getName()).isEqualTo("GK 4321");
        assertThat(cache.getInventory().get(2).getDistance()).isEqualTo(300F);
        assertThat(cache.getInventory().get(2).getOwner()).isNull();
        assertThat(cache.getInventory().get(2).getBrand()).isEqualTo(TrackableBrand.GEOKRETY);

        assertThat(cache.getInventory().get(3)).isEqualTo(trackable4);
        assertThat(cache.getInventory().get(3).getGeocode()).isEqualTo("UN0000");
        assertThat(cache.getInventory().get(3).getName()).isEqualTo("");
        assertThat(cache.getInventory().get(3).getDistance()).isEqualTo(-1F);
        assertThat(cache.getInventory().get(3).getOwner()).isNull();
        assertThat(cache.getInventory().get(3).getBrand()).isEqualTo(TrackableBrand.UNKNOWN);

        // test null inventory
        final Geocache cache1 = new Geocache();
        final List<Trackable> inventory3 = Collections.singletonList(trackable1);
        assertThat(cache1.getInventory()).isEmpty();

        cache1.mergeInventory(inventory3, EnumSet.of(TrackableBrand.TRAVELBUG));

        assertThat(cache1.getInventory()).hasSize(1);
        assertThat(cache1.getInventoryItems()).isEqualTo(1);

        assertThat(cache1.getInventory().get(0)).isEqualTo(trackable1);
        assertThat(cache1.getInventory().get(0).getGeocode()).isEqualTo("TB1234");
        assertThat(cache1.getInventory().get(0).getName()).isEqualTo("TB 1234");
        assertThat(cache1.getInventory().get(0).getDistance()).isEqualTo(-1F);
        assertThat(cache1.getInventory().get(0).getOwner()).isNull();
        assertThat(cache1.getInventory().get(0).getBrand()).isEqualTo(TrackableBrand.TRAVELBUG);
    }
distance circle must not be shown for waypoints of archived caches.
main/src/androidTest/java/cgeo/geocaching/models/GeocacheTest.java