@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(); }
@Test public void buyIllegalAmount() { User karcas = new User(); karcas.setName("Karcas"); karcas.setRoom(room1); 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)+")); DisplayInterface display = buyCommand.run("buy -2 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("That is an illegal amount.<br />\n")); }