@Test public void testValueForQuantity() throws Exception { ResValue value1 = new ResValue("value1", null, Quantity.MANY); ResValue value2 = new ResValue("value2", "Comment", Quantity.FEW); resItem.addValue(value1); resItem.addValue(value2); assertEquals(value1, resItem.valueForQuantity(value1.quantity)); assertEquals(value2, resItem.valueForQuantity(value2.quantity)); assertNull(resItem.valueForQuantity(Quantity.ONE)); }
@Test public void testAddSameQuantity() throws Exception { ResValue value1 = new ResValue("value1", null, Quantity.FEW); ResValue value2 = new ResValue("value2", "Comment", Quantity.FEW); assert resItem.addValue(value1); assert !resItem.addValue(value2); assertEquals(1, resItem.values.size()); assertNotEquals(value1, resItem.values.get(0)); assertEquals(value2, resItem.values.get(0)); }
@Test public void testAddValue() throws Exception { ResValue value = new ResValue("value", null, Quantity.OTHER); assert resItem.addValue(value); assertEquals(1, resItem.values.size()); assertEquals(value, resItem.values.get(0)); }
@Test public void testIsHasQuantities() throws Exception { assert !resItem.isHasQuantities(); resItem.addValue(new ResValue("Value1", null, Quantity.OTHER)); assert !resItem.isHasQuantities(); resItem.addValue(new ResValue("Value1", null, Quantity.MANY)); assert resItem.isHasQuantities(); resItem.removeValueForQuantity(Quantity.OTHER); assert resItem.isHasQuantities(); resItem.removeValueForQuantity(Quantity.MANY); assert !resItem.isHasQuantities(); }
@Test public void testRemove() throws Exception { ResValue value1 = new ResValue("value1", null, Quantity.MANY); ResValue value2 = new ResValue("value2", "Comment", Quantity.FEW); resItem.addValue(value1); resItem.addValue(value2); assert resItem.removeValue(value1); assertEquals(1, resItem.values.size()); assertNull(resItem.valueForQuantity(value1.quantity)); assertEquals(value2, resItem.valueForQuantity(value2.quantity)); assertEquals(value2, resItem.values.get(0)); assert !resItem.removeValue(value1); assertEquals(1, resItem.values.size()); assertEquals(value2, resItem.valueForQuantity(value2.quantity)); assertEquals(value2, resItem.values.get(0)); }
private ResItem prepareResItem(String key, ResValue[] values) { ResItem resItem = new ResItem(key); for (ResValue value : values) resItem.addValue(value); return resItem; }
@Test public void testMerge() throws Exception { ResValue value1 = new ResValue("value1", null, Quantity.OTHER); ResValue value2 = new ResValue("value2", "Comment", Quantity.FEW); ResValue value3 = new ResValue("value3", "Comment2", Quantity.ZERO); resItem.addValue(value1); resItem.addValue(value2); resItem.addValue(value3); ResItem resItem2 = new ResItem(resItem.key + "_"); // Merge should work independent from res key ResValue value4 = new ResValue("value4", null, Quantity.OTHER); ResValue value5 = new ResValue("value5", "Comment", Quantity.FEW); ResValue value6 = new ResValue("value6", "Comment2", Quantity.TWO); resItem2.addValue(value4); resItem2.addValue(value5); resItem2.addValue(value6); assert resItem.merge(resItem2) == resItem; assertEquals(4, resItem.values.size()); assertNotEquals(value1, resItem.valueForQuantity(Quantity.OTHER)); assertNotEquals(value2, resItem.valueForQuantity(Quantity.FEW)); assertEquals(value3, resItem.valueForQuantity(Quantity.ZERO)); assertEquals(value4, resItem.valueForQuantity(Quantity.OTHER)); assertEquals(value5, resItem.valueForQuantity(Quantity.FEW)); assertEquals(value6, resItem.valueForQuantity(Quantity.TWO)); }