@Test
  public void shouldThrowErrorWhenInsertingInvalidProductForAProgram() {
    Program program = make(a(defaultProgram));
    when(programRepository.getIdByCode(program.getCode())).thenReturn(1L);
    ProgramProduct programProduct = new ProgramProduct(program, new Product(), 10, true);

    expectedEx.expect(Matchers.dataExceptionMatcher("product.code.invalid"));

    programProductRepository.save(programProduct);
  }
  @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 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);
  }
  @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);
  }