Skip to content

Commit

Permalink
Fix Statement and SubStatement Object Builder does not copy all prope…
Browse files Browse the repository at this point in the history
…rties when objectType is Agent (#207)
  • Loading branch information
Selindek authored Aug 8, 2023
1 parent 27e863c commit d10c0c9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @see <a href="https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#actor">xAPI Actor</a>
*/
@Getter
@SuperBuilder
@SuperBuilder(toBuilder = true)
@ToString
@NoArgsConstructor
@EqualsAndHashCode(exclude = "name")
Expand Down
6 changes: 1 addition & 5 deletions xapi-model/src/main/java/dev/learning/xapi/model/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.With;
import lombok.experimental.SuperBuilder;

/**
Expand All @@ -21,11 +19,9 @@
*
* @see <a href="https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#agent">xAPI Agent</a>
*/
@With
@Getter
@SuperBuilder
@SuperBuilder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@JsonIgnoreProperties(value = {"firstName", "lastName"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public Builder agentAuthority(Consumer<Agent.Builder<?, ?>> authority) {
public Builder object(StatementObject object) {

if (object instanceof final Agent agent && AgentObjectType.AGENT != agent.getObjectType()) {
this.object = agent.withObjectType(AgentObjectType.AGENT);
this.object = agent.toBuilder().objectType(AgentObjectType.AGENT).build();
} else {
this.object = object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public Builder verb(Verb verb) {
public Builder object(SubStatementObject object) {

if (object instanceof final Agent agent && AgentObjectType.AGENT != agent.getObjectType()) {
this.object = agent.withObjectType(AgentObjectType.AGENT);
this.object = agent.toBuilder().objectType(AgentObjectType.AGENT).build();
} else {
this.object = object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasNoJsonPath;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -1688,7 +1690,7 @@ void whenSigningStatementThenSignatureIsValid()
}

@Test
void whenBuildingStatementWithAgentObjectWithoutObjectTypeThenStatementObjectObjectTypeIsNotNull() {
void whenBuildingStatementWithAgentObjectWithoutObjectTypeThenStatementObjectObjectTypeWasSet() {

final Agent agent = Agent.builder().name("A N Other").objectType(null).build();

Expand All @@ -1703,8 +1705,9 @@ void whenBuildingStatementWithAgentObjectWithoutObjectTypeThenStatementObjectObj

.build();

// Then Statement Object ObjectType Is Not Null
assertThat(((Agent) statement.getObject()).getObjectType(), is(notNullValue()));
// Then Statement Object ObjectType Was Set
assertThat((Agent) statement.getObject(),
allOf(hasProperty("objectType", is(notNullValue())), hasProperty("name", is("A N Other"))));

}

Expand Down

0 comments on commit d10c0c9

Please sign in to comment.