Skip to content

Commit

Permalink
Add Action Log model unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladay committed Jul 12, 2023
1 parent b06ad1c commit 35f3128
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/test/java/org/tdl/vireo/model/ActionLogTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.tdl.vireo.model;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Calendar;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.provider.Arguments;
import org.mockito.InjectMocks;
import org.springframework.test.util.ReflectionTestUtils;

public class ActionLogTest extends AbstractModelTest<ActionLog> {

@InjectMocks
private ActionLog actionLog;

/**
* The getPrivate() does not work via getParameterStream() and is manually tested here.
*
* This may be because the method is called "isPrivateFlag()" rather than "getPrivateFlag()".
*/
@Test
public void testGetSettings() {
boolean value = false;

ReflectionTestUtils.setField(actionLog, "privateFlag", value);

assertEquals(value, actionLog.isPrivateFlag(), GETTER_MESSAGE);
}

/**
* The privateFlag() does not work via getParameterStream() and is manually tested here.
*/
@Test
public void testSetSettings() {
boolean value = false;

// Set the flag to something other than false to confirm setter works.
ReflectionTestUtils.setField(actionLog, "privateFlag", true);

actionLog.setPrivateFlag(value);

assertEquals(value, ReflectionTestUtils.getField(getInstance(), "privateFlag"), SETTER_MESSAGE);
}

@Override
protected ActionLog getInstance() {
return actionLog;
}

protected static Stream<Arguments> provideGetterParameters() {
return getParameterStream();
}

protected static Stream<Arguments> provideSetterParameters() {
return getParameterStream();
}

private static Stream<Arguments> getParameterStream() {
return Stream.of(
Arguments.of("submissionStatus", new SubmissionStatus()),
Arguments.of("user", new User()),
Arguments.of("actionDate", Calendar.getInstance()),
Arguments.of("entry", "value")
);
}

}

0 comments on commit 35f3128

Please sign in to comment.