public static void testInventory() { final Geocache cache = new Geocache(); final Trackable trackable = new Trackable(); final List<Trackable> inventory = new ArrayList<>(Collections.singletonList(trackable)); cache.setInventory(inventory); assertThat(cache.getInventory()).isEqualTo(inventory); assertThat(cache.getInventoryItems()).isEqualTo(inventory.size()); }
public static void testMergeInventory() { final Geocache cache = new Geocache(); final List<Trackable> inventory1 = new ArrayList<>(4); // TB to be updated final Trackable trackable1 = new Trackable(); trackable1.setGeocode("TB1234"); trackable1.setName("TB 1234"); trackable1.forceSetBrand(TrackableBrand.TRAVELBUG); inventory1.add(trackable1); // TB to be updated final Trackable trackable2 = new Trackable(); trackable2.setGeocode("GK1234"); trackable2.setName("GK 1234"); 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); // new TB final List<Trackable> inventory2 = new ArrayList<>(3); final Trackable trackable5 = new Trackable(); trackable5.setGeocode("SW1234"); trackable5.setName("SW 1234"); trackable5.setDistance(100F); trackable5.forceSetBrand(TrackableBrand.SWAGGIE); inventory2.add(trackable5); // TB updater final Trackable trackable6 = new Trackable(); trackable6.setGeocode("GK1234"); 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); assertThat(cache.getInventory()).hasSize(5); assertThat(cache.getInventoryItems()).isEqualTo(5); assertThat(cache.getInventory().get(0)).isEqualTo(trackable1); assertThat(cache.getInventory().get(0).getGeocode()).isEqualTo("TB1234"); assertThat(cache.getInventory().get(0).getName()).isEqualTo("TB 1234"); assertThat(cache.getInventory().get(0).getDistance()).isEqualTo(-1F); assertThat(cache.getInventory().get(0).getOwner()).isNull(); assertThat(cache.getInventory().get(0).getBrand()).isEqualTo(TrackableBrand.TRAVELBUG); assertThat(cache.getInventory().get(1)).isEqualTo(trackable2); assertThat(cache.getInventory().get(1).getGeocode()).isEqualTo("GK1234"); assertThat(cache.getInventory().get(1).getName()).isEqualTo("GK 1234"); assertThat(cache.getInventory().get(1).getDistance()).isEqualTo(200F); assertThat(cache.getInventory().get(1).getOwner()).isNull(); assertThat(cache.getInventory().get(1).getBrand()).isEqualTo(TrackableBrand.GEOKRETY); assertThat(cache.getInventory().get(2)).isEqualTo(trackable4); assertThat(cache.getInventory().get(2).getGeocode()).isEqualTo("UN0000"); assertThat(cache.getInventory().get(2).getName()).isEqualTo(""); assertThat(cache.getInventory().get(2).getDistance()).isEqualTo(-1F); assertThat(cache.getInventory().get(2).getOwner()).isNull(); assertThat(cache.getInventory().get(2).getBrand()).isEqualTo(TrackableBrand.UNKNOWN); assertThat(cache.getInventory().get(3)).isEqualTo(trackable5); assertThat(cache.getInventory().get(3).getGeocode()).isEqualTo("SW1234"); assertThat(cache.getInventory().get(3).getName()).isEqualTo("SW 1234"); assertThat(cache.getInventory().get(3).getDistance()).isEqualTo(100F); assertThat(cache.getInventory().get(3).getOwner()).isNull(); assertThat(cache.getInventory().get(3).getBrand()).isEqualTo(TrackableBrand.SWAGGIE); assertThat(cache.getInventory().get(4)).isEqualTo(trackable7); assertThat(cache.getInventory().get(4).getGeocode()).isEqualTo("GK4321"); assertThat(cache.getInventory().get(4).getName()).isEqualTo("GK 4321"); assertThat(cache.getInventory().get(4).getDistance()).isEqualTo(300F); assertThat(cache.getInventory().get(4).getOwner()).isNull(); assertThat(cache.getInventory().get(4).getBrand()).isEqualTo(TrackableBrand.GEOKRETY); }