Skip to content

Commit

Permalink
added constructor to Event that copies the values into the new instance
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlehansen committed May 26, 2017
1 parent a304f2b commit 372cae4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/no/fint/event/model/Event.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.fint.event.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.ArrayList;
Expand All @@ -14,6 +15,7 @@
*
* @param <T> Type of the objects in the {@link #data} field
*/
@EqualsAndHashCode
public class Event<T> implements Serializable {
/**
* A unique id for an event. It should be a UUID generated by <code>UUID.randomUUID().toString()</code>
Expand Down Expand Up @@ -66,6 +68,24 @@ public Event() {
this.data = new ArrayList<>();
}

/**
* Constructor that copies values from the input Event object into the new Event object.
*
* @param event contains values that will be copied into the new instance
*/
@SuppressWarnings("unchecked")
public Event(Event event) {
this.corrId = event.getCorrId();
this.action = event.getAction();
this.status = event.getStatus();
this.time = event.getTime();
this.orgId = event.getOrgId();
this.source = event.getSource();
this.client = event.getClient();
this.message = event.getMessage();
this.data = event.getData();
}

/**
* Constructor that sets up an {@link Status#NEW} Event.
*
Expand Down
9 changes: 9 additions & 0 deletions src/test/groovy/no/fint/event/model/EventSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ class EventSpec extends Specification {
event.action == 'GET_ALL'
}

def "Copy values from old event object into new"() {
when:
def originalEvent = new Event('rogfk.no', 'FK1', 'GET_ALL', 'VFS')
Event<String> newEvent = new Event<>(originalEvent)

then:
newEvent == originalEvent
}

def "Check if event is health check when action is null"() {
when:
def event = new Event()
Expand Down

0 comments on commit 372cae4

Please sign in to comment.