CategorySummaryOperator { @MasterSelection public ItemInfo selectAvailableItem(List<ItemInfo> candidates, SalesDetail sales) { DateTime dateTime = sales.getSalesDateTime(); dateBuffer.setElapsedDays(DateUtil.getDayFromDate( dateTime.getYear(), dateTime.getMonth(), dateTime.getDay())); for (ItemInfo item : candidates) { if (item.getBeginDate().compareTo(dateBuffer) <= 0 && dateBuffer.compareTo(item.getEndDate()) <= 0) { return item; } } return null; }  @MasterCheck abstract boolean checkStore(
            @Key(group = "store_code") StoreInfo info,
            @Key(group = "store_code") SalesDetail sales); @MasterJoin(selection = "selectAvailableItem") abstract JoinedSalesInfo joinItemInfo(ItemInfo info, SalesDetail sales); @MasterSelection ItemInfo selectAvailableItem(List<ItemInfo> candidates, SalesDetail sales); @Summarize abstract CategorySummary summarizeByCategory(JoinedSalesInfo info); @Update void setErrorMessage(ErrorRecord record, String message);  }
@Test public void selectAvailableItem() { List<ItemInfo> candidates = new ArrayList<ItemInfo>(); candidates.add(item("A", 1, 10)); candidates.add(item("B", 11, 20)); candidates.add(item("C", 21, 30)); CategorySummaryOperator operator = new CategorySummaryOperatorImpl(); ItemInfo item1 = operator.selectAvailableItem(candidates, sales(1)); ItemInfo item5 = operator.selectAvailableItem(candidates, sales(5)); ItemInfo item10 = operator.selectAvailableItem(candidates, sales(10)); ItemInfo item15 = operator.selectAvailableItem(candidates, sales(11)); ItemInfo item20 = operator.selectAvailableItem(candidates, sales(20)); ItemInfo item30 = operator.selectAvailableItem(candidates, sales(30)); ItemInfo item31 = operator.selectAvailableItem(candidates, sales(31)); assertThat(item1.getCategoryCodeAsString(), is("A")); assertThat(item5.getCategoryCodeAsString(), is("A")); assertThat(item10.getCategoryCodeAsString(), is("A")); assertThat(item15.getCategoryCodeAsString(), is("B")); assertThat(item20.getCategoryCodeAsString(), is("B")); assertThat(item30.getCategoryCodeAsString(), is("C")); assertThat(item31, is(nullValue())); }