@Test(groups="Integration") // because slow public void testNothingHappensWhenSensorRepublishedUnchanged() { final ImmutableSet<Integer> input1 = ImmutableSet.of(1, 2, 3); testEntity.sensors().set(DEFAULT_SENSOR, input1); addSetChangePolicy(true, true); testEntity.sensors().set(DEFAULT_SENSOR, input1); // Neither effector should be invoked. Asserts.continually(CollectionFunctionals.sizeSupplier(onAddedParameters), Predicates.equalTo(0)); Asserts.continually(CollectionFunctionals.sizeSupplier(onRemovedParameters), Predicates.equalTo(0)); }
@Test public void testOnRemovedEffectorNotCalledWhenItemsAdded() throws Exception { addSetChangePolicy(false, true); final Set<Integer> values = ImmutableSet.of(1); testEntity.sensors().set(DEFAULT_SENSOR, values); Asserts.continually(CollectionFunctionals.sizeSupplier(onRemovedParameters), Predicates.equalTo(0)); }
@Test public void testOnAddedEffectorNotCalledWhenItemRemoved() throws Exception { testEntity.sensors().set(DEFAULT_SENSOR, ImmutableSet.of(1)); addSetChangePolicy(true, false); testEntity.sensors().set(DEFAULT_SENSOR, ImmutableSet.<Integer>of()); Asserts.continually(CollectionFunctionals.sizeSupplier(onRemovedParameters), Predicates.equalTo(0)); }
@Test public void testCollectionsAreConvertedToSets() { final List<Integer> input1 = ImmutableList.of( 1, 1, 2, 3, 4, 5, 2, 3, 4, 5); final List<Integer> input2 = ImmutableList.of(6, 5, 4, 3, 3); addSetChangePolicy(true, true); testEntity.sensors().set(DEFAULT_SENSOR, input1); Asserts.eventually(new ConfigBagValueKeySupplier(onAddedParameters), Predicates.<Collection<Object>>equalTo(ImmutableSet.<Object>of(1, 2, 3, 4, 5))); Asserts.continually(CollectionFunctionals.sizeSupplier(onRemovedParameters), Predicates.equalTo(0)); onAddedParameters.clear(); testEntity.sensors().set(DEFAULT_SENSOR, input2); Asserts.eventually(new ConfigBagValueKeySupplier(onAddedParameters), Predicates.<Collection<Object>>equalTo(ImmutableSet.<Object>of(6))); Asserts.eventually(new ConfigBagValueKeySupplier(onRemovedParameters), Predicates.<Collection<Object>>equalTo(ImmutableSet.<Object>of(1, 2))); }