@Test public void firstNAdd() { Transformers.<MyObject>firstN(Properties.constant(1)).transform(fromList, toList); fromList.add(new MyObject("x")); fromList.add(0, new MyObject("y")); assertEquals("[y]", toList.toString()); }
@Test public void targetHasNoMoreThanNElements() { ObservableSingleItemList<MyObject> targetList = new ObservableSingleItemList<>(); fromList.add(new MyObject("x")); Transformers.<MyObject>firstN(Properties.constant(1)).transform(fromList, targetList); fromList.add(0, new MyObject("y")); assertEquals("[y]", targetList.toString()); }
@Test public void firstNInitial() { fromList.add(new MyObject("a")); fromList.add(new MyObject("b")); fromList.add(new MyObject("c")); Transformers.<MyObject>firstN(Properties.constant(2)).transform(fromList, toList); assertEquals("[a, b]", toList.toString()); }
@Test public void firstNRemove() { fromList.add(new MyObject("a")); fromList.add(new MyObject("b")); fromList.add(new MyObject("c")); Transformers.<MyObject>firstN(Properties.constant(1)).transform(fromList, toList); fromList.remove(2); fromList.remove(0); assertEquals("[b]", toList.toString()); }
@Test public void firstNdecreaseN() { fromList.add(new MyObject("a")); fromList.add(new MyObject("b")); fromList.add(new MyObject("c")); ValueProperty<Integer> prop = new ValueProperty<>(2); Transformers.<MyObject>firstN(prop).transform(fromList, toList); prop.set(0); assertEquals("[]", toList.toString()); }