InStockProductSearchQueryBuilder extends AbstractSearchQueryBuilderImpl implements ProductSearchQueryBuilder<Query> { @Override public List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value) { String strValue = "1"; if (value instanceof Collection) { if (CollectionUtils.isNotEmpty((Collection) value)) { strValue = "0".equals(((Collection) value).iterator().next()) ? "0" : "1"; } } else { strValue = "0".equals(value) ? "0" : "1"; } return Collections.singletonList(createNumericQuery(PRODUCT_SHOP_INSTOCK_FLAG_FIELD + strValue, navigationContext.getCustomerShopId())); }  @Override List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value);  }
@Test public void testCreateQueryChainInStock() throws Exception { final NavigationContext<Query> navigationContext = this.context.mock(NavigationContext.class, "navigationContext"); this.context.checking(new Expectations() {{ oneOf(navigationContext).getCustomerShopId(); will(returnValue(1010L)); }}); final List<Query> query = new InStockProductSearchQueryBuilder().createQueryChain(navigationContext, "any", "1"); assertNotNull(query); assertEquals(1, query.size()); assertEquals("productInStockFlagShopId1:[1010 TO 1010]", query.get(0).toString()); this.context.assertIsSatisfied(); }
@Test public void testCreateQueryChainNoStock() throws Exception { final NavigationContext<Query> navigationContext = this.context.mock(NavigationContext.class, "navigationContext"); this.context.checking(new Expectations() {{ oneOf(navigationContext).getCustomerShopId(); will(returnValue(1010L)); }}); final List<Query> query = new InStockProductSearchQueryBuilder().createQueryChain(navigationContext, "any", "0"); assertNotNull(query); assertEquals(1, query.size()); assertEquals("productInStockFlagShopId0:[1010 TO 1010]", query.get(0).toString()); this.context.assertIsSatisfied(); }