@Test public void testCreateHeroProductForEmptyCategory() { when(heroProduct01.getCategory()).thenReturn(category01); when(heroProduct01.getIndexedType()).thenReturn(solrIndexedType01); when(defaultHeroProductDefinitionDao.findSolrHeroProductDefinitionsByCategory( category01, solrIndexedType01)) .thenReturn(Collections.EMPTY_LIST); when(Boolean.valueOf(ctx.isNew(heroProduct01))).thenReturn(Boolean.TRUE); try { solrHeroProductValidator.onValidate(heroProduct01, ctx); } catch (final InterceptorException ie) { fail("should have created the hero product instead!"); } }
@Test public void testCreateDuplicatedHeroProduct() { when(heroProduct01.getCategory()).thenReturn(category01); when(heroProduct01.getIndexedType()).thenReturn(solrIndexedType01); when(defaultHeroProductDefinitionDao.findSolrHeroProductDefinitionsByCategory( category01, solrIndexedType01)) .thenReturn(Collections.singletonList(heroProduct01)); when(Boolean.valueOf(ctx.isNew(heroProduct01))).thenReturn(Boolean.TRUE); try { solrHeroProductValidator.onValidate(heroProduct01, ctx); fail("should have thrown InterceptorException since hero product existed!"); } catch (final InterceptorException ie) { // expected } }
@Before public void setUp() { MockitoAnnotations.initMocks(this); solrHeroProductValidator = new SolrHeroProductValidator(); solrHeroProductValidator.setHeroProductDefinitionDao(defaultHeroProductDefinitionDao); }