@Test
public void testSetRepositoryVersion() throws Exception {

  expect(sch.getVersion()).andReturn(UNKNOWN_VERSION);
  expect(serviceComponent.isVersionAdvertised()).andReturn(Boolean.TRUE);
  RepositoryVersionDAO dao = createNiceMock(RepositoryVersionDAO.class);
  RepositoryVersionEntity entity = createNiceMock(RepositoryVersionEntity.class);
  expect(entity.getVersion()).andReturn("2.4.0.0").once();
  expect(dao.findByPK(1L)).andReturn(entity).once();
  expect(dao.merge(entity)).andReturn(entity).once();
  replayAll();
  String newVersion = VALID_NEW_VERSION;
  HostComponentVersionAdvertisedEvent event = new HostComponentVersionAdvertisedEvent(cluster, sch, newVersion, 1L);
  // !!! avoid injector for test class
  Field field = StackVersionListener.class.getDeclaredField("repositoryVersionDAO");
  field.setAccessible(true);
  field.set(listener, dao);
  listener.onAmbariEvent(event);
  verifyAll();
}