@Test
  public void shouldThrowErrorWhenInsertingProductForInvalidProgram() {
    Product product = make(a(defaultProduct));
    Program program = make(a(defaultProgram));
    ProgramProduct programProduct = new ProgramProduct(program, product, 10, true);
    when(programRepository.getIdByCode(programProduct.getProgram().getCode()))
        .thenThrow(new DataException("exception"));

    expectedEx.expect(DataException.class);
    expectedEx.expectMessage("exception");
    programProductRepository.save(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 shouldCreateProgramProductDTOFromProgramProduct() {

    ProgramProduct programProduct = make(a(defaultProgramProduct));

    programProduct.getProduct().setCategory(new ProductCategory("P1", "Product Name", 1));

    ProgramProductDTO programProductDTO = new ProgramProductDTO(programProduct);

    assertThat(programProductDTO.getProductCode(), is(programProduct.getProduct().getCode()));
    assertThat(
        programProductDTO.getProductName(), is(programProduct.getProduct().getPrimaryName()));
    assertThat(programProductDTO.getProgramCode(), is(programProduct.getProgram().getCode()));
    assertThat(programProductDTO.getProgramName(), is(programProduct.getProgram().getName()));
    assertThat(
        programProductDTO.getCategory(), is(programProduct.getProduct().getCategory().getName()));
    assertThat(
        programProductDTO.getDescription(), is(programProduct.getProduct().getDescription()));
    assertThat(
        programProductDTO.getUnit(), is(programProduct.getProduct().getDosesPerDispensingUnit()));
  }