コード例 #1
0
  @Test
  public void shouldFindImportGoodAndCurrentRow() {
    // mock import good
    ImportGood importGoodMock = new ImportGood();
    importGoodMock.setStage(STAGE.CONTRACT.toNumber());
    importGoodMock.setEstimateContract(1l);
    when(importGoodDao.findOneBy(any(ImportGood.class))).thenReturn(importGoodMock);

    // mock import good row
    when(importGoodRowDao.findById(anyLong())).thenReturn(new ImportGoodRow());

    Response tryGet = importGoodService.findImportGoodAndCurrentRow(1l);
    assertTrue(tryGet.isSuccess());

    assertFalse(importGoodService.findImportGoodAndCurrentRow(-1l).isSuccess());

    importGoodMock = new ImportGood();
    importGoodMock.setStage(STAGE.UNDEFINED.toNumber());
    when(importGoodDao.findOneBy(any(ImportGood.class))).thenReturn(importGoodMock);
    assertTrue(importGoodService.findImportGoodAndCurrentRow(1l).isSuccess());

    importGoodMock = new ImportGood();
    importGoodMock.setStage(STAGE.DESIGN.toNumber());
    when(importGoodDao.findOneBy(any(ImportGood.class))).thenReturn(importGoodMock);
    assertFalse(importGoodService.findImportGoodAndCurrentRow(1l).isSuccess());
  }
コード例 #2
0
  @Test
  public void shouldUpdateProgress() {
    // mock imported good
    ImportGood goodMock = new ImportGood();
    goodMock.setStage(STAGE.CONTRACT.toNumber());
    goodMock.setEstimateContract(1l);
    when(importGoodDao.findById(anyLong())).thenReturn(goodMock);

    // mock imported row
    ImportGoodRow rowMock = new ImportGoodRow();
    rowMock.setDuration(1);
    rowMock.setTimeline(DateTime.now().minusDays(2).toDate());
    when(importGoodRowDao.findById(anyLong())).thenReturn(rowMock);

    // mock update row
    when(importGoodRowDao.updateForce(any(ImportGoodRow.class))).thenReturn(true);

    // all pass test
    ImportGoodRow param = new ImportGoodRow();
    param.setDuration(1);
    param.setStage(STAGE.CONTRACT.toNumber());
    param.setProgress(DateTime.now().minusDays(3).toDate());
    Response tryUpdate = importGoodService.updateProgress(param, 1l, 1);
    assertFalse(tryUpdate.isSuccess());

    param.setStage(STAGE.CONTRACT.toNumber());
    param.setProgress(DateTime.now().toDate());
    tryUpdate = importGoodService.updateProgress(param, 1l, 1);
    assertTrue(tryUpdate.isSuccess());

    assertFalse(importGoodService.updateProgress(null, null, null).isSuccess());

    when(importGoodRowDao.findById(anyLong())).thenReturn(null);
    assertFalse(importGoodService.updateProgress(param, 1l, 1).isSuccess());
  }
コード例 #3
0
  @Test
  public void shouldFindByModuleId() {
    List<ImportGood> goodListMock = Lists.newArrayList();
    ImportGood good = new ImportGood();
    good.setEstimateContract(1l);
    goodListMock.add(good);
    when(importGoodDao.findBy(any(ImportGood.class))).thenReturn(goodListMock);

    when(importGoodRowDao.findByIds(anyList())).thenReturn(Lists.<ImportGoodRow>newArrayList());

    Response tryGet = importGoodService.findByModuleId(1l);
    assertTrue(tryGet.isSuccess());

    assertFalse(importGoodService.findByModuleId(null).isSuccess());
  }