Skip to content

Commit

Permalink
Fix typoe in WorkflowStepTest name and add missing test coverage.
Browse files Browse the repository at this point in the history
The Heritable setting functions need to be tested as well.
  • Loading branch information
kaladay committed Jul 12, 2023
1 parent 1752ced commit 2654907
Showing 1 changed file with 120 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import edu.tamu.weaver.data.model.WeaverEntity;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.provider.Arguments;
import org.mockito.InjectMocks;
import org.tdl.vireo.model.inheritance.HeritableComponent;

public class WorflowStepTest extends AbstractModelTest<WorkflowStep> {
public class WorkflowStepTest extends AbstractModelTest<WorkflowStep> {

@InjectMocks
private WorkflowStep workflowStep;
Expand Down Expand Up @@ -201,6 +203,76 @@ public void testReplaceOriginalNoteOnNotFound() {
assertFalse(workflowStep.getAggregateNotes().contains(otherNote), "The old Note is found in the Aggregate Notes.");
}

@Test
public void testAddHeritableModelUsingNote() {
List<Note> originalNotes = new ArrayList<>();
List<FieldProfile> fieldProfiles = new ArrayList<>();
Note newNote = new Note();

newNote.setId(1L);

workflowStep.setOriginalNotes(originalNotes);
workflowStep.setAggregateNotes(originalNotes);

workflowStep.setOriginalFieldProfiles(fieldProfiles);
workflowStep.setAggregateFieldProfiles(fieldProfiles);

workflowStep.addAggregateHeritableModel(newNote);

assertTrue(workflowStep.getOriginalNotes().contains(newNote), "The new Note is not found.");
assertEquals(workflowStep.getOriginalFieldProfiles().size(), 0, "The Original Field Profiles have a non-zero length.");

assertTrue(workflowStep.getAggregateNotes().contains(newNote), "The new Note is not found in the Aggregate Notes.");
assertEquals(workflowStep.getAggregateFieldProfiles().size(), 0, "The Aggregate Field Profiles have a non-zero length.");
}

@Test
public void testAddHeritableModelUsingFieldProfile() {
List<Note> originalNotes = new ArrayList<>();
List<FieldProfile> fieldProfiles = new ArrayList<>();
FieldProfile newFieldProfile = new FieldProfile();

newFieldProfile.setId(1L);

workflowStep.setOriginalNotes(originalNotes);
workflowStep.setAggregateNotes(originalNotes);

workflowStep.setOriginalFieldProfiles(fieldProfiles);
workflowStep.setAggregateFieldProfiles(fieldProfiles);

workflowStep.addAggregateHeritableModel(newFieldProfile);

assertTrue(workflowStep.getOriginalFieldProfiles().contains(newFieldProfile), "The new Note is not found.");
assertEquals(workflowStep.getOriginalNotes().size(), 0, "The Original Notes have a non-zero length.");

assertTrue(workflowStep.getAggregateFieldProfiles().contains(newFieldProfile), "The new Note is not found in the Aggregate Notes.");
assertEquals(workflowStep.getAggregateNotes().size(), 0, "The Aggregate Notes have a non-zero length.");
}

@Test
public void testAddHeritableModelUsingOther() {
List<Note> originalNotes = new ArrayList<>();
List<FieldProfile> fieldProfiles = new ArrayList<>();

OtherComponent newComponent = new OtherComponent();

newComponent.setId(1L);

workflowStep.setOriginalNotes(originalNotes);
workflowStep.setAggregateNotes(originalNotes);

workflowStep.setOriginalFieldProfiles(fieldProfiles);
workflowStep.setAggregateFieldProfiles(fieldProfiles);

workflowStep.addAggregateHeritableModel(newComponent);

assertEquals(workflowStep.getOriginalFieldProfiles().size(), 0, "The Original Field Profiles have a non-zero length.");
assertEquals(workflowStep.getOriginalNotes().size(), 0, "The Original Notes have a non-zero length.");

assertEquals(workflowStep.getAggregateFieldProfiles().size(), 0, "The Aggregate Field Profiles have a non-zero length.");
assertEquals(workflowStep.getAggregateNotes().size(), 0, "The Aggregate Notes have a non-zero length.");
}

@Override
protected WorkflowStep getInstance() {
return workflowStep;
Expand All @@ -224,6 +296,7 @@ private static Stream<Arguments> getParameterStream() {
return Stream.of(
Arguments.of("name", "value"),
Arguments.of("overrideable", true),
Arguments.of("overrideable", false),
Arguments.of("aggregateFieldProfiles", fieldProfiles),
Arguments.of("aggregateNotes", notes),
Arguments.of("instructions", "instruction"),
Expand All @@ -234,4 +307,50 @@ private static Stream<Arguments> getParameterStream() {
);
}

protected class OtherComponent implements HeritableComponent<Object> {
private Long id = 0L;

@Override
public int compareTo(WeaverEntity arg0) {
return 0;
}

@Override
public Long getId() {
return id;
}

@Override
public void setId(Long arg0) {
this.id = arg0;
}

@Override
public void setOriginating(Object originatingHeritableModel) {
}

@Override
public Object getOriginating() {
return null;
}

@Override
public void setOriginatingWorkflowStep(WorkflowStep originatingWorkflowStep) {
}

@Override
public WorkflowStep getOriginatingWorkflowStep() {
return null;
}

@Override
public Boolean getOverrideable() {
return null;
}

@Override
public Object clone() {
return new Object();
}
}
}

0 comments on commit 2654907

Please sign in to comment.