Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ public void copied_object_has_target_type_that_is_not_linked_to_source_object()
assertEquals(TargetType.OPI, source.type());
assertEquals(TargetType.COMPONENT, copied.type());
}

@Test
public void copied_object_has_macros_that_are_not_linked_to_source_object() {
final String sourcePropertyValue = "SOURCE";
final String copiedPropertyValue = "COPIED";

// Arrange
source.getProperties().get(0).setValue(sourcePropertyValue);
TargetDescription copied = new TargetDescription(source);

// Act (should not affect property of source).
copied.getProperties().get(0).setValue(copiedPropertyValue);

// Assert
assertEquals(source.getProperties().get(0).getValue(), sourcePropertyValue);
assertEquals(copied.getProperties().get(0).getValue(), copiedPropertyValue);
}

@Test
public void copied_object_has_same_properties_as_source_object_with_no_name_changes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
Expand Down Expand Up @@ -98,10 +99,7 @@ private ComponentDescription(ComponentDescription other, boolean isTopLevelCopy,
this.type = other.type;
this.target = other.target != null ? new TargetDescription(other.target) : null;

this.pvs = new ArrayList<>();
for (PV pv : other.pvs) {
this.pvs.add(new PV(pv));
}
this.pvs = other.pvs().stream().map(PV::new).collect(Collectors.toList());

this.components = new ArrayList<>();
for (ComponentDescription cd : other.components) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public class Property extends ModelObject {
public Property() {
}

/**
* Clones an existing property.
*
* @param other the property to clone
*/
public Property(Property other) {
this(other.key, other.value);
}

/**
* Instantiates a new property.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
Expand All @@ -41,7 +42,7 @@ public class TargetDescription {

@XmlElementWrapper(name = "properties")
@XmlElement(name = "property", type = Property.class)
private ArrayList<Property> properties = new ArrayList<>();
private List<Property> properties = new ArrayList<>();

/**
* Default constructor, required due to existence of copy constructor.
Expand Down Expand Up @@ -69,7 +70,7 @@ public TargetDescription(String name, TargetType type) {
public TargetDescription(TargetDescription other) {
this.name = other.name;
this.type = other.type;
this.properties = new ArrayList<>(other.getProperties());
this.properties = other.getProperties().stream().map(Property::new).collect(Collectors.toList());
}

/**
Expand Down