IndexVolumeGroupDaoImpl implements IndexVolumeGroupDao { @Override public IndexVolumeGroup get(final int id) { return JooqUtil.contextResult(indexDbConnProvider, context -> context .select() .from(INDEX_VOLUME_GROUP) .where(INDEX_VOLUME_GROUP.ID.eq(id)) .fetchOptional() .map(RECORD_TO_INDEX_VOLUME_GROUP_MAPPER) .orElse(null)); } @Inject  IndexVolumeGroupDaoImpl(final IndexDbConnProvider indexDbConnProvider); @Override IndexVolumeGroup getOrCreate(final IndexVolumeGroup indexVolumeGroup); @Override IndexVolumeGroup update(IndexVolumeGroup indexVolumeGroup); @Override IndexVolumeGroup get(final int id); @Override IndexVolumeGroup get(final String name); @Override List<String> getNames(); @Override List<IndexVolumeGroup> getAll(); @Override void delete(final String name); @Override void delete(int id);  }
@Test void testCreateWithDuplicateName() { final Long now = System.currentTimeMillis(); final String groupName = TestData.createVolumeGroupName(); final IndexVolumeGroup createdOnce = createGroup(groupName); final Long createdTimeMs = createdOnce.getCreateTimeMs(); assertThat(createdTimeMs).isCloseTo(now, Offset.offset(100L)); final IndexVolumeGroup retrievedOnce = indexVolumeGroupDao.get(createdOnce.getId()); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } final IndexVolumeGroup createdTwice = createGroup(groupName); final IndexVolumeGroup retrievedTwice = indexVolumeGroupDao.get(createdTwice.getId()); assertThat(Stream.of(createdOnce, retrievedOnce, createdTwice, retrievedTwice)) .allSatisfy(i -> { assertThat(i.getCreateTimeMs()).isEqualTo(createdTimeMs); assertThat(i.getUpdateTimeMs()).isEqualTo(createdTimeMs); assertThat(i.getCreateUser()).isEqualTo(TestModule.TEST_USER); assertThat(i.getUpdateUser()).isEqualTo(TestModule.TEST_USER); }); }