GroupDAO { public long createGroup(String name, String creator, String description, ImmutableMap<String, String> metadata) { GroupsRecord r = dslContext.newRecord(GROUPS); String jsonMetadata; try { jsonMetadata = mapper.writeValueAsString(metadata); } catch (JsonProcessingException e) { throw Throwables.propagate(e); } long now = OffsetDateTime.now().toEpochSecond(); r.setName(name); r.setCreatedby(creator); r.setCreatedat(now); r.setUpdatedby(creator); r.setUpdatedat(now); r.setDescription(description); r.setMetadata(jsonMetadata); r.store(); return r.getId(); } private  GroupDAO(DSLContext dslContext, GroupMapper groupMapper, ObjectMapper mapper); long createGroup(String name, String creator, String description, ImmutableMap<String, String> metadata); void deleteGroup(Group group); Optional<Group> getGroup(String name); Optional<Group> getGroupById(long id); ImmutableSet<Group> getGroups();  }
@Test public void createGroup() { int before = tableSize(); groupDAO.createGroup("newGroup", "creator3", "", ImmutableMap.of()); assertThat(tableSize()).isEqualTo(before + 1); List<String> names = groupDAO.getGroups() .stream() .map(Group::getName) .collect(toList()); assertThat(names).contains("newGroup"); }
@Test(expected = DataAccessException.class) public void willNotCreateDuplicateGroup() throws Exception { groupDAO.createGroup("group1", "creator1", "", ImmutableMap.of()); }