@Test
public void setIdentifierProvider_customIdentifier_keyMapperUsesIdentifier() {

    Item first = new Item(1L, "first");
    Item second = new Item(2L, "middle");
    List<Item> items = new ArrayList<>(Arrays.asList(first, second));
    Grid<Item> component = new Grid<>();
    // We create a generic data provider to test the identity
    // handling behavior in generic data view
    DataProvider<Item, Void> dataProvider = new DataProvider<Item, Void>() {
        @Override
        public boolean isInMemory() {
            return true;
        }
        @Override
        public int size(Query<Item, Void> query) {
            return 2;
        }
        @Override
        public Stream<Item> fetch(Query<Item, Void> query) {
            return Stream.of(first, second);
        }
        @Override
        public void refreshItem(Item item) {
        }
        @Override
        public void refreshAll() {
        }
        @Override
        public Registration addDataProviderListener(
                DataProviderListener<Item> listener) {
            return null;
        }
    };
    // Generic grid data view
    DataView<Item> dataView = component.setItems(dataProvider);
    DataKeyMapper<Item> keyMapper = component.getDataCommunicator()
            .getKeyMapper();
    items.forEach(keyMapper::key);
    Assert.assertFalse(keyMapper.has(new Item(1L, "non-present")));
    dataView.setIdentifierProvider(Item::getId);
    Assert.assertTrue(keyMapper.has(new Item(1L, "non-present")));
    dataView.setIdentifierProvider(IdentifierProvider.identity());
    Assert.assertFalse(keyMapper.has(new Item(1L, "non-present")));
    // In-memory grid data view
    dataView = component.setItems(DataProvider.ofCollection(items));
    // We need to repopulate the keyMapper after setting a new data provider
    items.forEach(keyMapper::key);
    Assert.assertFalse(keyMapper.has(new Item(1L, "non-present")));
    dataView.setIdentifierProvider(Item::getId);
    Assert.assertTrue(keyMapper.has(new Item(1L, "non-present")));
    dataView.setIdentifierProvider(IdentifierProvider.identity());
    Assert.assertFalse(keyMapper.has(new Item(1L, "non-present")));
}