@Test
  public void test_copy_basic_participant_properties_create_new_features() {

    Participant sourceParticipant =
        new DefaultParticipant(InteractorUtils.createUnknownBasicInteractor());
    sourceParticipant.setStoichiometry(new DefaultStoichiometry(3));
    sourceParticipant
        .getCausalRelationships()
        .add(
            new DefaultCausalRelationship(
                new DefaultCvTerm("decrease"), new DefaultParticipant(new DefaultProtein("p1"))));
    sourceParticipant.setBiologicalRole(new DefaultCvTerm("enzyme"));
    sourceParticipant.getAliases().add(new DefaultAlias("test alias"));
    sourceParticipant.getXrefs().add(new DefaultXref(new DefaultCvTerm("test database"), "xxxx"));
    sourceParticipant
        .getAnnotations()
        .add(new DefaultAnnotation(new DefaultCvTerm("test comment"), "comment"));
    ((Collection<Feature>) sourceParticipant.getFeatures())
        .add(new DefaultFeature("test", "test feature"));

    Participant targetParticipant = new DefaultParticipant(new DefaultProtein("p2"));

    ParticipantCloner.copyAndOverrideBasicParticipantProperties(
        sourceParticipant, targetParticipant, true);

    Assert.assertEquals(1, targetParticipant.getFeatures().size());
    Assert.assertFalse(
        targetParticipant.getFeatures().iterator().next()
            == sourceParticipant.getFeatures().iterator().next());
    Assert.assertTrue(
        DefaultFeatureBaseComparator.areEquals(
            (Feature) targetParticipant.getFeatures().iterator().next(),
            (Feature) sourceParticipant.getFeatures().iterator().next()));
  }
  @Test
  public void test_copy_modelled_participant_properties() {

    ModelledParticipant sourceParticipant =
        new DefaultModelledParticipant(InteractorUtils.createUnknownBasicInteractor());
    sourceParticipant.setStoichiometry(new DefaultStoichiometry(3));
    sourceParticipant
        .getCausalRelationships()
        .add(
            new DefaultCausalRelationship(
                new DefaultCvTerm("decrease"), new DefaultParticipant(new DefaultProtein("p1"))));
    sourceParticipant.setBiologicalRole(new DefaultCvTerm("enzyme"));
    sourceParticipant.getAliases().add(new DefaultAlias("test alias"));
    sourceParticipant.getXrefs().add(new DefaultXref(new DefaultCvTerm("test database"), "xxxx"));
    sourceParticipant
        .getAnnotations()
        .add(new DefaultAnnotation(new DefaultCvTerm("test comment"), "comment"));
    sourceParticipant.addFeature(new DefaultModelledFeature("test", "test feature"));
    sourceParticipant.setInteraction(new DefaultModelledInteraction());

    ModelledParticipant targetParticipant =
        new DefaultModelledParticipant(new DefaultProtein("p2"));

    ParticipantCloner.copyAndOverrideModelledParticipantProperties(
        sourceParticipant, targetParticipant, false);

    Assert.assertEquals(1, targetParticipant.getXrefs().size());
    Assert.assertEquals(1, targetParticipant.getAnnotations().size());
    Assert.assertEquals(1, targetParticipant.getAliases().size());
    Assert.assertEquals(1, targetParticipant.getFeatures().size());
    Assert.assertNull(targetParticipant.getInteraction());
    Assert.assertTrue(
        targetParticipant.getXrefs().iterator().next()
            == sourceParticipant.getXrefs().iterator().next());
    Assert.assertTrue(
        targetParticipant.getAliases().iterator().next()
            == sourceParticipant.getAliases().iterator().next());
    Assert.assertTrue(
        targetParticipant.getAnnotations().iterator().next()
            == sourceParticipant.getAnnotations().iterator().next());
    Assert.assertTrue(
        targetParticipant.getFeatures().iterator().next()
            == sourceParticipant.getFeatures().iterator().next());
    Assert.assertTrue(targetParticipant.getInteractor() == sourceParticipant.getInteractor());
    Assert.assertTrue(targetParticipant.getStoichiometry() == sourceParticipant.getStoichiometry());
    Assert.assertTrue(
        targetParticipant.getBiologicalRole() == sourceParticipant.getBiologicalRole());
    Assert.assertTrue(
        targetParticipant.getCausalRelationships().iterator().next()
            == sourceParticipant.getCausalRelationships().iterator().next());
    Assert.assertTrue(
        targetParticipant.getFeatures().iterator().next().getParticipant() == sourceParticipant);
  }
  @Test
  @Ignore
  public void test_write_interaction_inferred()
      throws XMLStreamException, IOException, IllegalRangeException {
    BinaryInteractionEvidence interaction = new DefaultNamedBinaryInteractionEvidence();
    ParticipantEvidence participant =
        new DefaultNamedParticipantEvidence(InteractorUtils.createUnknownBasicInteractor());
    ParticipantEvidence participant2 =
        new DefaultNamedParticipantEvidence(InteractorUtils.createUnknownBasicInteractor());
    ParticipantEvidence participant3 =
        new DefaultNamedParticipantEvidence(InteractorUtils.createUnknownBasicInteractor());
    ParticipantEvidence participant4 =
        new DefaultNamedParticipantEvidence(InteractorUtils.createUnknownBasicInteractor());
    // two inferred interactiosn f1, f2, f3 and f3,f4
    FeatureEvidence f1 = new DefaultFeatureEvidence();
    f1.getRanges().add(RangeUtils.createRangeFromString("1-4"));
    FeatureEvidence f2 = new DefaultFeatureEvidence();
    f2.getRanges().add(RangeUtils.createRangeFromString("1-4"));
    FeatureEvidence f3 = new DefaultFeatureEvidence();
    f1.getLinkedFeatures().add(f2);
    f1.getLinkedFeatures().add(f3);
    f2.getLinkedFeatures().add(f1);
    f2.getLinkedFeatures().add(f3);
    f3.getLinkedFeatures().add(f1);
    f3.getLinkedFeatures().add(f2);
    participant.addFeature(f1);
    participant2.addFeature(f2);
    participant3.addFeature(f3);
    interaction.addParticipant(participant);
    interaction.addParticipant(participant2);
    elementCache.clear();

    XmlNamedBinaryInteractionEvidenceWriter writer =
        new XmlNamedBinaryInteractionEvidenceWriter(createStreamWriter(), this.elementCache);
    writer.write(interaction);
    streamWriter.flush();

    Assert.assertEquals(this.interaction_inferred, output.toString());
  }
  @Test
  public void test_write_interaction()
      throws XMLStreamException, IOException, IllegalRangeException {
    BinaryInteractionEvidence interaction = new DefaultNamedBinaryInteractionEvidence();
    ParticipantEvidence participant =
        new DefaultNamedParticipantEvidence(InteractorUtils.createUnknownBasicInteractor());
    interaction.addParticipant(participant);
    elementCache.clear();

    XmlNamedBinaryInteractionEvidenceWriter writer =
        new XmlNamedBinaryInteractionEvidenceWriter(createStreamWriter(), this.elementCache);
    writer.write(interaction);
    streamWriter.flush();

    Assert.assertEquals(this.interaction, output.toString());
  }
  @Test
  public void test_copy_participant_evidence_properties_create_new_features() {

    ParticipantEvidence sourceParticipant =
        new DefaultParticipantEvidence(InteractorUtils.createUnknownBasicInteractor());
    sourceParticipant.setStoichiometry(new DefaultStoichiometry(3));
    sourceParticipant
        .getCausalRelationships()
        .add(
            new DefaultCausalRelationship(
                new DefaultCvTerm("decrease"), new DefaultParticipant(new DefaultProtein("p1"))));
    sourceParticipant.setBiologicalRole(new DefaultCvTerm("enzyme"));
    sourceParticipant.getAliases().add(new DefaultAlias("test alias"));
    sourceParticipant.getXrefs().add(new DefaultXref(new DefaultCvTerm("test database"), "xxxx"));
    sourceParticipant
        .getAnnotations()
        .add(new DefaultAnnotation(new DefaultCvTerm("test comment"), "comment"));
    sourceParticipant.addFeature(new DefaultFeatureEvidence("test", "test feature"));
    sourceParticipant.setInteraction(new DefaultInteractionEvidence());
    sourceParticipant.setExperimentalRole(new DefaultCvTerm("bait"));
    sourceParticipant.setExpressedInOrganism(new DefaultOrganism(-1));
    sourceParticipant.getExperimentalPreparations().add(new DefaultCvTerm("test preparation"));
    sourceParticipant
        .getConfidences()
        .add(new DefaultConfidence(new DefaultCvTerm("author-score"), "high"));
    sourceParticipant
        .getParameters()
        .add(new DefaultParameter(new DefaultCvTerm("kd"), new ParameterValue(new BigDecimal(3))));

    ParticipantEvidence targetParticipant =
        new DefaultParticipantEvidence(new DefaultProtein("p2"));

    ParticipantCloner.copyAndOverrideParticipantEvidenceProperties(
        sourceParticipant, targetParticipant, true);

    Assert.assertEquals(1, targetParticipant.getFeatures().size());
    Assert.assertFalse(
        targetParticipant.getFeatures().iterator().next()
            == sourceParticipant.getFeatures().iterator().next());
    Assert.assertTrue(
        DefaultFeatureBaseComparator.areEquals(
            targetParticipant.getFeatures().iterator().next(),
            sourceParticipant.getFeatures().iterator().next()));
    Assert.assertTrue(
        targetParticipant.getFeatures().iterator().next().getParticipant() == targetParticipant);
  }
  @Test
  public void test_write_interaction_attributes()
      throws XMLStreamException, IOException, IllegalRangeException {
    BinaryInteractionEvidence interaction = new DefaultNamedBinaryInteractionEvidence();
    ParticipantEvidence participant =
        new DefaultNamedParticipantEvidence(InteractorUtils.createUnknownBasicInteractor());
    interaction.addParticipant(participant);
    interaction.getAnnotations().add(new DefaultAnnotation(new DefaultCvTerm("test2")));
    interaction.getAnnotations().add(new DefaultAnnotation(new DefaultCvTerm("test3")));
    interaction.setComplexExpansion(CvTermUtils.createMICvTerm("spoke expansion", "MI:1060"));
    elementCache.clear();

    XmlNamedBinaryInteractionEvidenceWriter writer =
        new XmlNamedBinaryInteractionEvidenceWriter(createStreamWriter(), this.elementCache);
    writer.write(interaction);
    streamWriter.flush();

    Assert.assertEquals(this.interaction_attributes, output.toString());
  }
  @Test
  public void test_write_interaction_alias()
      throws XMLStreamException, IOException, IllegalRangeException {
    NamedInteraction interaction = new DefaultNamedBinaryInteractionEvidence();
    interaction
        .getAliases()
        .add(new DefaultAlias(new DefaultCvTerm("synonym"), "interaction synonym"));
    interaction.getAliases().add(new DefaultAlias("test"));
    ParticipantEvidence participant =
        new DefaultNamedParticipantEvidence(InteractorUtils.createUnknownBasicInteractor());
    interaction.addParticipant(participant);
    elementCache.clear();

    XmlNamedBinaryInteractionEvidenceWriter writer =
        new XmlNamedBinaryInteractionEvidenceWriter(createStreamWriter(), this.elementCache);
    writer.write((BinaryInteractionEvidence) interaction);
    streamWriter.flush();

    Assert.assertEquals(this.interaction_aliases, output.toString());
  }