コード例 #1
0
  public void testModifyActiveTrade() {
    MasterController mc = new MasterController();
    mc.initializeController();
    UserDatabase db = mc.getUserDB();
    DatabaseController.deleteAllData();
    try {
      User bob = DatabaseController.createUser("Bob");
      User joel = DatabaseController.createUser("Joel");

      List<Skill> skillz1 = new ArrayList<Skill>(), skillz2 = new ArrayList<Skill>();
      skillz1.add(new Skill(db, "...YEP", "FOO", "desc", true, new ArrayList<Image>()));

      TradeList tl = bob.getTradeList();
      tl.createTrade(db, bob, joel, skillz2);

      Trade t = tl.getMostRecentTrade(db);

      // Modify An Active Trade
      t.getHalfForUser(bob).setOffer(skillz1);
      List<ID> ids = new ArrayList<ID>();
      for (Skill skill : skillz1) {
        ids.add(skill.getSkillID());
      }
      assertEquals(t.getHalfForUser(bob).getOffer(), ids);

      // Delete An Active Trade
      tl.delete(t);
      assertTrue(tl.getActiveTrades(db).size() == 0);
    } catch (UserAlreadyExistsException e) {
      assertTrue(false);
    }
  }
コード例 #2
0
  public void testCounterOfferTradeRequest() {
    MasterController mc = new MasterController();
    mc.initializeController();
    UserDatabase db = mc.getUserDB();
    DatabaseController.deleteAllData();
    try {
      User user = DatabaseController.createUser("u");
      User user2 = DatabaseController.createUser("u2");
      List<Skill> offer = new ArrayList<Skill>();
      List<Skill> counterOffer = new ArrayList<Skill>();

      offer.add(
          new Skill(db, "illlllll", "LLLLLLLLLLLLLLLL", "desc", true, new ArrayList<Image>()));
      counterOffer.add(
          new Skill(db, "Counter skill", "meta", "desc", true, new ArrayList<Image>()));

      Trade trade = user.getTradeList().createTrade(db, user, user2, offer);
      trade.getHalfForUser(user2).setAccepted(false);
      trade.getHalfForUser(user2).setOffer(counterOffer);
      List<ID> ids = new ArrayList<ID>();
      for (Skill skill : counterOffer) {
        ids.add(skill.getSkillID());
      }
      assertEquals(trade.getHalfForUser(user2).getOffer(), ids);
    } catch (UserAlreadyExistsException e) {
      assertTrue(false);
    }
  }
コード例 #3
0
  public void testRefuseTradeRequest() {
    MasterController mc = new MasterController();
    mc.initializeController();
    UserDatabase db = mc.getUserDB();
    DatabaseController.deleteAllData();
    try {
      User user = DatabaseController.createUser("u");
      User user2 = DatabaseController.createUser("u2");
      List<Skill> offer = new ArrayList<Skill>();

      offer.add(
          new Skill(db, "illlllll", "LLLLLLLLLLLLLLLL", "desc", true, new ArrayList<Image>()));

      Trade trade = user.getTradeList().createTrade(db, user, user2, offer);
      // decline the trade
      trade.getHalfForUser(user2).setAccepted(false);
      DatabaseController.save();
      assertTrue(trade.isActive());
      // delete the trade
      user2.getTradeList().delete(user2.getTradeList().getMostRecentTrade(db));
      DatabaseController.save();
      assertTrue(user.getTradeList().getActiveTrades(db).size() == 0);
    } catch (UserAlreadyExistsException e) {
      assertTrue(false);
    }
  }