Ejemplo n.º 1
0
  @BeforeMethod
  public void setUpMethod() throws Exception {
    itemBean = new ItemBean();
    setField(ItemBean.class, "logBean", itemBean, logBean);

    itemDef = new ItemDefinition();
    itemDef.setId(1);
    itemDef.setName("ring");
    itemDef.setAdject1("nice");
    itemDef.setAdject2("golden");
    itemDef.setAdject3("friendship");
    itemDef.setCopper(5);

    ring = new NormalItem();
    ring.setItemDefinition(itemDef);

    room1 = new Room();
    room1.setId(1);
    room1.setContents("You are in a small room.");

    karn = new User();
    karn.setName("Karn");
    karn.setRoom(room1);

    File file = new File(Constants.getMudfilepath() + File.separator + "Karn.log");
    PrintWriter writer = new PrintWriter(file);
    writer.close();
  }
Ejemplo n.º 2
0
  @Test
  public void buyBound() throws NamingException {
    Shopkeeper karcas = new Shopkeeper();
    karcas.setName("Karcas");
    karcas.setRoom(room1);

    HashSet<Person> persons = new HashSet<>();
    persons.add(karn);
    persons.add(karcas);
    setField(Room.class, "persons", room1, persons);
    setField(Person.class, "copper", karn, 1111);
    ring.getItemDefinition().setBound(true);

    HashSet<Item> items = new HashSet<>();
    items.add(ring);
    setField(Person.class, "items", karcas, items);
    BuyCommand buyCommand = new BuyCommand("buy( (\\w|-)+){1,4} from (\\w)+");
    buyCommand.setCallback(commandRunner);
    assertThat(buyCommand.getRegExpr(), equalTo("buy( (\\w|-)+){1,4} from (\\w)+"));
    new Expectations() // an "expectation block"
    {

      {
        commandRunner.getItemBean();
        result = itemBean;
      }
    };
    DisplayInterface display = buyCommand.run("buy ring from karcas", karn);
    assertThat(display, not(nullValue()));
    assertThat(display.getBody(), equalTo("You are in a small room."));
    String log = karn.getLog(0);
    assertThat(log, equalTo("You cannot buy that item.<br />\nYou did not buy anything.<br />\n"));
  }