### Question:
SetAttributeActionConfig implements ActionConfig { @Override public StatefulAction createAction(Map<String, Object> variables) { Preconditions.checkState(address != null, "Must specify an address"); Preconditions.checkState(attributeName != null, "Must specify an attributeName"); Preconditions.checkState(attributeValue != null, "Must specify an attributeValue"); Preconditions.checkState(attributeType != null, "Must specify an attributeType"); SetAndRestore action = null; if(reevaluateCondition) { action = new ConditionalSetAndRestore( FunctionFactory.toActionContextFunction( TemplatedValue.transform( FunctionFactory.INSTANCE.getToAddress(), address.toTemplate() ) ), FunctionFactory.INSTANCE.createConstant(attributeName), FunctionFactory.toActionContextFunction( TemplatedValue.transform( FunctionFactory.createCoerceFunction(attributeType), attributeValue.toTemplate() ) ), unit.toMillis(duration), conditionQuery==null?null:FunctionFactory.toModelPredicate(this.conditionQuery.toTemplate(), variables) ); }else { action = new SetAndRestore( FunctionFactory.toActionContextFunction( TemplatedValue.transform( FunctionFactory.INSTANCE.getToAddress(), address.toTemplate() ) ), FunctionFactory.INSTANCE.createConstant(attributeName), FunctionFactory.toActionContextFunction( TemplatedValue.transform( FunctionFactory.createCoerceFunction(attributeType), attributeValue.toTemplate() ) ), unit.toMillis(duration), conditionQuery==null?Predicates.alwaysTrue():FunctionFactory.toModelPredicate(this.conditionQuery.toTemplate(), variables) ); } return action; } SetAttributeActionConfig(); TemplatedExpression getAddress(); void setAddress(TemplatedExpression address); String getAttributeName(); void setAttributeName(String attribute); TemplatedExpression getAttributeValue(); void setAttributeValue(TemplatedExpression value); AttributeType getAttributeType(); void setAttributeType(AttributeType type); int getDuration(); void setDuration(int duration); TimeUnit getUnit(); void setUnit(TimeUnit unit); TemplatedExpression getConditionQuery(); void setConditionQuery(TemplatedExpression conditionQuery); @Override String getType(); boolean isReevaluateCondition(); void setReevaluateCondition(boolean reevaluateCondition); @Override StatefulAction createAction(Map<String, Object> variables); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final String TYPE; }### Answer:
@Test public void testCreateEmpty() { SetAttributeActionConfig empty = new SetAttributeActionConfig(); try { empty.createAction(ImmutableMap.of()); fail("Allowed to be creqted without required params"); } catch(IllegalStateException e) { } }
@Test public void testCreateWithDuration() { SetAttributeActionConfig config = createFullConfig(); StatefulAction action = config.createAction(null); assertTrue(action instanceof SetAndRestore); }