MonthlyReportRepository extends AbstractRepository<MonthlyReport> { public MonthlyReport findByYearAndMonth(int year, int month) { TypedQuery<MonthlyReport> typedQuery = entityManager.createNamedQuery(MonthlyReport.FIND_BY_YEAR_AND_MONTH, MonthlyReport.class); typedQuery.setParameter("year", year); typedQuery.setParameter("month", month); return typedQuery.getSingleResult(); }  MonthlyReport findByYearAndMonth(int year, int month); MonthlyReport findById(Long id);  }
@Test public void testFindByYearAndMonth() throws Exception { MonthlyReport march = MonthlyReport.from(3L, 2014, 3, new byte[SIZE_10MB], DateTime.now()); MonthlyReport april = MonthlyReport.from(4L, 2014, 4, new byte[SIZE_10MB], DateTime.now()); monthlyReportRepository.save(march); monthlyReportRepository.save(april); MonthlyReport foundMarch = monthlyReportRepository.findByYearAndMonth(2014, 3); MonthlyReport foundApril = monthlyReportRepository.findByYearAndMonth(2014, 4); assertThat(foundMarch).isEqualTo(march); assertThat(foundMarch.getMonthlyReportPdf().length).isEqualTo(SIZE_10MB); assertThat(foundApril).isEqualTo(april); assertThat(foundApril.getMonthlyReportPdf().length).isEqualTo(SIZE_10MB); }