Staff extends OrmActiveRecord<Staff> { public static Staff register(final OrmRepository rep, final PasswordEncoder encoder, RegStaff p) { Validator.validate((v) -> v.checkField(!get(rep, p.id).isPresent(), "id", ErrorKeys.DuplicateId)); return p.create(encoder.encode(p.plainPassword)).save(rep); }  Actor actor(); Staff change(final OrmRepository rep, final PasswordEncoder encoder, final ChgPassword p); Staff change(final OrmRepository rep, ChgStaff p); static Optional<Staff> get(final OrmRepository rep, final String id); static Staff load(final OrmRepository rep, final String id); static List<Staff> find(final OrmRepository rep, final FindStaff p); static Staff register(final OrmRepository rep, final PasswordEncoder encoder, RegStaff p);  }
@Test public void 社員情報を登録する() { tx(() -> { Staff staff = Staff.register(rep, encoder, new RegStaff("new", "newName", "password")); assertThat(staff, allOf( hasProperty("id", is("new")), hasProperty("name", is("newName")))); assertTrue(encoder.matches("password", staff.getPassword())); try { Staff.register(rep, encoder, new RegStaff("sample", "newName", "password")); fail(); } catch (ValidationException e) { assertThat(e.getMessage(), is(ErrorKeys.DuplicateId)); } }