@Test
  public void getSelectedItem() {
    selectionModel.setSelectedItem(PERSON_B);

    Assert.assertEquals(PERSON_B, selectionModel.getSelectedItem().get());

    selectionModel.deselect(PERSON_B);
    Assert.assertFalse(selectionModel.getSelectedItem().isPresent());
  }
  @Test
  public void reselect() {
    selectionModel.select(PERSON_B);
    selectionModel.select(PERSON_C);

    assertEquals(PERSON_C, selectionModel.getSelectedItem().orElse(null));

    assertFalse(selectionModel.isSelected(PERSON_A));
    assertFalse(selectionModel.isSelected(PERSON_B));
    assertTrue(selectionModel.isSelected(PERSON_C));

    assertEquals(Optional.of(PERSON_C), selectionModel.getSelectedItem());

    assertEquals(Arrays.asList(PERSON_B, PERSON_C), selectionChanges);
  }
  @Before
  public void setUp() {
    grid = new Grid<>();
    grid.setItems(PERSON_A, PERSON_B, PERSON_C);
    selectionModel = (SingleSelectionModelImpl<Person>) grid.getSelectionModel();

    selectionChanges = new ArrayList<>();
    selectionModel.addSingleSelectionListener(e -> selectionChanges.add(e.getValue()));
  }
  @SuppressWarnings({"serial"})
  @Test
  public void addValueChangeListener() {
    AtomicReference<SingleSelectionListener<String>> selectionListener = new AtomicReference<>();
    Registration registration = Mockito.mock(Registration.class);
    Grid<String> grid = new Grid<>();
    grid.setItems("foo", "bar");
    String value = "foo";
    SingleSelectionModelImpl<String> select =
        new SingleSelectionModelImpl<String>() {
          @Override
          public Registration addSingleSelectionListener(SingleSelectionListener<String> listener) {
            selectionListener.set(listener);
            return registration;
          }

          @Override
          public Optional<String> getSelectedItem() {
            return Optional.of(value);
          }
        };

    AtomicReference<ValueChangeEvent<?>> event = new AtomicReference<>();
    Registration actualRegistration =
        select.addSingleSelectionListener(
            evt -> {
              Assert.assertNull(event.get());
              event.set(evt);
            });
    Assert.assertSame(registration, actualRegistration);

    selectionListener
        .get()
        .selectionChange(new SingleSelectionEvent<>(grid, select.asSingleSelect(), true));

    Assert.assertEquals(grid, event.get().getComponent());
    Assert.assertEquals(value, event.get().getValue());
    Assert.assertTrue(event.get().isUserOriginated());
  }
  @Test
  public void selectDeselect() {

    selectionModel.select(PERSON_B);
    selectionModel.deselect(PERSON_B);

    assertFalse(selectionModel.getSelectedItem().isPresent());

    assertFalse(selectionModel.isSelected(PERSON_A));
    assertFalse(selectionModel.isSelected(PERSON_B));
    assertFalse(selectionModel.isSelected(PERSON_C));

    assertFalse(selectionModel.getSelectedItem().isPresent());

    assertEquals(Arrays.asList(PERSON_B, null), selectionChanges);
  }
  @Test(expected = IllegalStateException.class)
  public void selectionModelChanged_usingPreviousSelectionModel_throws() {
    grid.setSelectionMode(SelectionMode.MULTI);

    selectionModel.select(PERSON_A);
  }
 @Override
 protected void setSelectedFromClient(String key) {
   super.setSelectedFromClient(key);
 }
 @Override
 public void generateData(String item, JsonObject jsonObject) {
   super.generateData(item, jsonObject);
   // capture updated row
   generatedData.put(item, isSelected(item));
 }