Employment extends Accountability<Company, Employee> { public static Company getEmployer(Employee employee, Date date) { return getRepository().createNamedQuery("Employment.getEmployer") .addParameter("employee", employee).addParameter("date", date).singleResult(); } protected  Employment();  Employment(Company company, Employee employee, Date date); static Company getEmployer(Employee employee, Date date); static List<Employee> getEmployees(Company employer, Date date); @Override String toString();  }
@Test public final void testGetEmployer() { OrganisationUtils organisationUtils = new OrganisationUtils(); Date date = DateUtils.date(2012, 1, 3); Company company = organisationUtils.createCompany("总公司", date); Employee zhangsan = organisationUtils.createEmployee("张三", date); Employee lisi = organisationUtils.createEmployee("李四", date); new Employment(company, zhangsan, date).save(); assertThat("张三的雇主应该是company", Employment.getEmployer(zhangsan, DateUtils.date(2012, 1, 3)), is(company)); assertThat("李四的雇主不是company", Employment.getEmployer(lisi, DateUtils.date(2012, 1, 3)), not(is(company))); }