@Before public void setUp() throws Exception { programProductRepository = new ProgramProductRepository( programRepository, programProductMapper, productRepository, programProductPriceMapper); programProduct = make(a(ProgramProductBuilder.defaultProgramProduct)); programProduct.setModifiedDate(new Date()); when(productRepository.getIdByCode("productCode")).thenReturn(1L); when(programProductMapper.getByProgramAndProductId(anyLong(), anyLong())) .thenReturn(programProduct); }
@Test public void shouldInsertProgramForAProduct() { Program program = new Program(); program.setCode("P1"); Product product = new Product(); product.setCode("P2"); ProgramProduct programProduct = new ProgramProduct(program, product, 10, true); programProduct.setModifiedDate(new Date()); when(programProductMapper.getByProgramAndProductId(anyLong(), anyLong())).thenReturn(null); programProductRepository.save(programProduct); verify(programProductMapper).insert(programProduct); }