コード例 #1
0
 @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
 public List<Experiment> list(String schearch) {
   if (Strings.isNullOrEmpty(schearch))
     return repository.all(QExperiment.experiment, createConstructiorExpression());
   return repository.list(
       QExperiment.experiment,
       QExperiment.experiment.name.containsIgnoreCase(schearch),
       createConstructiorExpression());
 }
コード例 #2
0
  @Test(expected = AppException.class)
  public void deleteWithError() throws AppException {
    Mockito.when(repository.findById(ID, SampleEntity.class))
        .thenThrow(new IllegalArgumentException("Error"));

    service.delete(ID);

    Mockito.verify(repository).delete(createSampleEntity(ID, null));
  }
コード例 #3
0
  @Test
  public void delete() throws AppException {
    Mockito.when(repository.findById(ID, SampleEntity.class))
        .thenReturn(createSampleEntity(ID, null));

    service.delete(ID);

    Mockito.verify(repository).delete(createSampleEntity(ID, null));
  }
コード例 #4
0
  @Test
  public void create() throws AppException {
    SampleEntity sample = createSampleEntity(ID, "IPI");
    Mockito.when(repository.save(sample)).thenReturn(createSampleEntity(ID, "IPI"));

    SampleEntity newSample = service.create(sample);

    Mockito.verify(repository).save(sample);
    MatcherAssert.assertThat(newSample.id, Matchers.equalTo(ID));
  }
コード例 #5
0
  @Test
  public void find() throws AppException {
    Mockito.when(repository.findById(ID, SampleEntity.class))
        .thenReturn(createSampleEntity(ID, null));

    SampleEntity sample = service.find(ID);

    Mockito.verify(repository).findById(ID, SampleEntity.class);
    MatcherAssert.assertThat(sample, Matchers.equalTo(createSampleEntity(ID, null)));
  }
コード例 #6
0
  @Test
  public void listAll() {
    Mockito.when(repository.all(QSampleEntity.sampleEntity, QSampleEntity.sampleEntity))
        .thenReturn(getList());
    List<SampleEntity> list = service.list("");

    Mockito.verify(repository).all(QSampleEntity.sampleEntity, QSampleEntity.sampleEntity);

    MatcherAssert.assertThat(list, Matchers.hasSize(1));
    MatcherAssert.assertThat(list, Matchers.contains(createSampleEntity(ID, null)));
  }
コード例 #7
0
  @Test
  public void listWithError() {
    String schearch = "search";
    Mockito.when(
            repository.list(
                QSampleEntity.sampleEntity,
                service.getFilter(schearch),
                QSampleEntity.sampleEntity))
        .thenReturn(getList());
    List<SampleEntity> list = service.list(schearch);

    Mockito.verify(repository)
        .list(QSampleEntity.sampleEntity, service.getFilter(schearch), QSampleEntity.sampleEntity);

    MatcherAssert.assertThat(list, Matchers.hasSize(1));
    MatcherAssert.assertThat(list, Matchers.contains(createSampleEntity(ID, null)));
  }
コード例 #8
0
 @Test(expected = AppException.class)
 public void createWithError() throws AppException {
   when(repository.save(createSampleEntity(ID, null)))
       .thenThrow(new IllegalArgumentException("Error"));
   service.create(createSampleEntity(ID, null));
 }
コード例 #9
0
 @Test(expected = AppException.class)
 public void findByIdWithError() throws AppException {
   when(repository.findById(ID, SampleEntity.class))
       .thenThrow(new IllegalArgumentException("Error"));
   service.find(ID);
 }