コード例 #1
0
  @Test
  public void test8() throws ParseException {

    String routeInfo = "1";
    String date = "2015-12-01";
    String time = "00:00";
    Route r = new Route();
    r.setRouteId(1);
    r.setRouteName("route");
    Direction d = new Direction();
    d.setDirectionId(2);
    Shedule s = new Shedule();
    s.setDirection(d);
    s.setStep(0);
    List<Shedule> steps = new ArrayList<Shedule>();
    steps.add(s);

    List<Train> trains = new ArrayList<Train>();

    Mockito.when(dao.getRoute(Integer.parseInt(routeInfo))).thenReturn(r);
    Mockito.when(dao.getShedulesOfRoute(r.getRouteId())).thenReturn(steps);
    Mockito.when(dao.getAllTrains()).thenReturn(trains);

    NewJourneyInfo info1 = new NewJourneyInfo(routeInfo, date, time, null, null, null, false);
    NewJourneyInfo info3 = planner.plan(info1);

    Assert.assertTrue(info3.getJourneyId() == null);
    Assert.assertTrue(info3.getRouteName() == null);
    Assert.assertTrue(info3.getTrain() == null);
    Assert.assertTrue(info3.isTrainsLack());
  }
コード例 #2
0
  @Test
  public void test2() throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    String routeInfo = "1";
    String date = "2015-01-01";
    String time = "00:00";
    Route r = new Route();
    r.setRouteId(1);
    r.setRouteName("route");
    Direction d = new Direction();
    d.setDirectionId(2);
    Shedule s = new Shedule();
    s.setDirection(d);
    s.setStep(0);
    List<Shedule> steps = new ArrayList<Shedule>();
    steps.add(s);
    Train train = new Train();
    train.setTrainId(3);
    List<Train> trains = new ArrayList<Train>();
    trains.add(train);
    Journey j = new Journey(4, r, train, sdf.parse(date));

    Mockito.when(dao.getRoute(Integer.parseInt(routeInfo))).thenReturn(r);
    Mockito.when(dao.getShedulesOfRoute(r.getRouteId())).thenReturn(steps);
    Mockito.when(dao.getAllTrains()).thenReturn(trains);
    Mockito.when(dao.getAllJourneysOfTrain(train.getTrainId()))
        .thenReturn(new ArrayList<Journey>());
    Mockito.when(dao.createJourney(train, r, sdf.parse(date))).thenReturn(j);

    NewJourneyInfo input = new NewJourneyInfo(routeInfo, date, time, null, null, null, false);
    NewJourneyInfo expected = new NewJourneyInfo(routeInfo, "", "", null, null, null, false);
    NewJourneyInfo result = planner.plan(input);

    Assert.assertTrue(result.getJourneyId() == expected.getJourneyId());
    Assert.assertTrue(result.getRouteInfo().equals(expected.getRouteInfo()));
    Assert.assertTrue(result.getRouteName() == expected.getRouteName());
    Assert.assertTrue(result.getTime().equals(expected.getTime()));
    Assert.assertTrue(result.getTrain() == expected.getTrain());
  }