### Question:
EventPropertyWriter extends PropertyWriter { public void addError(ErrorRef errorRef) { Error error = bpmn2.createError(); ErrorEventDefinition errorEventDefinition = bpmn2.createErrorEventDefinition(); addEventDefinition(errorEventDefinition); String errorCode = errorRef.getValue(); String errorId; if (StringUtils.nonEmpty(errorCode)) { error.setErrorCode(errorCode); CustomAttribute.errorName.of(errorEventDefinition).set(errorCode); errorId = errorCode; } else { errorId = UUID.uuid(); } error.setId(errorId); errorEventDefinition.setErrorRef(error); addRootElement(error); } EventPropertyWriter(Event event, VariableScope variableScope); abstract void setAssignmentsInfo(AssignmentsInfo assignmentsInfo); void addMessage(MessageRef messageRef); void addLink(LinkRef linkRef); void addSignal(SignalRef signalRef); void addSignalScope(SignalScope signalScope); void addError(ErrorRef errorRef); void addTerminate(); void addTimer(TimerSettings timerSettings); void addCondition(ConditionExpression condition); void addEscalation(EscalationRef escalationRef); void addCompensation(); void addSlaDueDate(SLADueDate slaDueDate);  }### Answer:
@Test public void testAddEmptyError() { final ArgumentCaptor<RootElement> captor = ArgumentCaptor.forClass(RootElement.class); ErrorRef errorRef = new ErrorRef(); propertyWriter.addError(errorRef); ErrorEventDefinition definition = getErrorDefinition(); assertNull(definition.getErrorRef().getErrorCode()); assertFalse(definition.getErrorRef().getId().isEmpty()); verify(propertyWriter).addRootElement(captor.capture()); Error error = (Error) captor.getValue(); assertNull(error.getErrorCode()); assertFalse(error.getId().isEmpty()); }
@Test public void testAddError() { final ArgumentCaptor<RootElement> captor = ArgumentCaptor.forClass(RootElement.class); ErrorRef errorRef = new ErrorRef(); errorRef.setValue(ERROR_CODE); propertyWriter.addError(errorRef); ErrorEventDefinition definition = getErrorDefinition(); Assert.assertEquals(ERROR_CODE, definition.getErrorRef().getErrorCode()); assertFalse(definition.getErrorRef().getId().isEmpty()); verify(propertyWriter).addRootElement(captor.capture()); Error error = (Error) captor.getValue(); Assert.assertEquals(ERROR_CODE, error.getErrorCode()); assertFalse(error.getId().isEmpty()); }