Currently I'm learning FitNesse. I have two different test tables in one test page and want to Add/Remove quantities in my "InventoryFixture" tables.
My problem is that I can't get the value of the quantity from "InventoryFixture" table using "myInventory" object. My object is to ensure that I'm working with same object each time and refers to class "InventoryFixture".
I'm using java in the development and extends ColumnFixture.
In class "AddRemoveItemFixture", I get the new items and add them to my quantity which is in class "InventoryFixture".
it seems I'm missing something, can anyone tell me what?
it seems I'm missing something, can anyone tell me what?
Here comes all my java code:
package fitNesseExample;
import fit.ColumnFixture;
public class InventoryFixture extends ColumnFixture{
private int quantity;
private int partNumber;
public int getQuantity(){
return quantity;
}
public void setQuantity(int quantity){
this.quantity = quantity;
}
public int getPartNumber() {
return partNumber;
}
public void setPartNumber(int partNumber) {
this.partNumber = partNumber;
}
public boolean valid(){
if(quantity>0){
return true;
}else{
return false;
}
}
public int addQuantities(int item){
int items = item;
return items;
}
}
In this class I add the new items by function addItems(), here comes the problem. myInventory.getQuantity() returns [0] instead of [28] so the total items is (0+5 = 5) NOT (28+5 = 33).
package fitNesseExample;
import fit.ColumnFixture;
public class AddRemoveItemFixture extends ColumnFixture{
public int partNumber;
public int newItems;
public InventoryFixture myInventory;
public void setNewItems(int newItems){
this.newItems = newItems;
}
public void setPartNumber(int partNumber) {
this.partNumber = partNumber;
}
public int addItems(){
myInventory = StaticInventory.getMyInventory();
int totalItems = myInventory.addQuantities(myInventory.getQuantity() + newItems);
myInventory.setQuantity(totalItems);
return myInventory.getQuantity();
}
}
I instantiate class InventoryFixture as:
package fitNesseExample;
import fit.ColumnFixture;
public abstract class StaticInventory extends ColumnFixture{
public static InventoryFixture myInventory;
public static InventoryFixture getMyInventory(){
if(myInventory == null) myInventory = new InventoryFixture();
return myInventory;
}
}
The problem is the first FitNesse table creates a new instance of InventoryFixture
, which is not the same instance as your static myInventory
. So the first table does not update myInventory
.