@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 shouldUpdateProgramProductIfExist() throws Exception { Long programId = 88L; Long productId = 99L; programProduct.setId(1L); when(programRepository.getIdByCode(anyString())).thenReturn(programId); when(productRepository.getIdByCode(anyString())).thenReturn(productId); programProductRepository.save(programProduct); assertThat(programProduct.getProgram().getId(), is(88L)); assertThat(programProduct.getProduct().getId(), is(99L)); verify(programProductMapper).update(programProduct); }
@Test public void shouldGetProgramProductByProgramAndProductCodes() throws Exception { ProgramProduct programProduct = make(a(ProgramProductBuilder.defaultProgramProduct)); final Long programId = 123L; when(programRepository.getIdByCode(PROGRAM_CODE)).thenReturn(programId); final Long productId = 12L; when(productRepository.getIdByCode(PRODUCT_CODE)).thenReturn(productId); ProgramProduct expectedProgramProduct = new ProgramProduct(); when(programProductMapper.getByProgramAndProductId(programId, productId)) .thenReturn(expectedProgramProduct); ProgramProduct result = programProductRepository.getByProgramAndProductCode(programProduct); verify(programRepository).getIdByCode(PROGRAM_CODE); verify(productRepository).getIdByCode(PRODUCT_CODE); verify(programProductMapper).getByProgramAndProductId(programId, productId); assertThat(result, is(expectedProgramProduct)); }