Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AB2D-6147] increase ab2d-events-client coverage #399

Merged
merged 12 commits into from
Jun 26, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public boolean equals(final Object o) {
if (otherTimeOfEvent != null) {
return false;
}
} else if (thisTimeOfEvent.toEpochSecond() != otherTimeOfEvent.toEpochSecond()) {
} else if (otherTimeOfEvent == null || thisTimeOfEvent.toEpochSecond() != otherTimeOfEvent.toEpochSecond()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this missing null check when writing the tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan to increase library version? may be later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks for catching that @smirnovaae! I forgot that part. I'll do it in another PR.

return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
package gov.cms.ab2d.eventclient.events;

import static org.junit.Assert.assertEquals;

import java.time.OffsetDateTime;
import java.time.ZoneOffset;

import org.junit.jupiter.api.Test;

import gov.cms.ab2d.eventclient.config.Ab2dEnvironment;

class LoggableEventTest {

// LoggableEvent is abstract, so we use a subclass instead
class MockLoggableEvent extends LoggableEvent {
public String asMessage() {
return "";
}
}

@Test
void testSetEnvironment() {
LoggableEvent event = new MockLoggableEvent();

event.setEnvironment("example");
assertEquals("example", event.getEnvironment());

event.setEnvironment(Ab2dEnvironment.LOCAL);
assertEquals("local", event.getEnvironment());
}

@Test
void testHashCodeCaseOne() {
LoggableEvent event = new MockLoggableEvent();
assertEquals(437864549, event.hashCode());
}

@Test
void testHashCodeCaseTwo() {
LoggableEvent event = new MockLoggableEvent();
event.setEnvironment("example");
event.setId(99L);
event.setAwsId("AWS");
event.setTimeOfEvent(OffsetDateTime.of(1, 1, 1, 1, 1, 1, 1, ZoneOffset.of("Z")));
event.setOrganization("CMS");
event.setJobId("1234");
assertEquals(1726282058, event.hashCode());
}

@Test
void testEqualsCaseOne() {
LoggableEvent event = new MockLoggableEvent();
assertEquals(true, event.equals(event));
}

@Test
void testEqualsCaseTwo() {
LoggableEvent event = new MockLoggableEvent();
Object other = new LoggableEventTest();
assertEquals(false, event.equals(other));
}

// testEqualsEnvironment //

@Test
void testEqualsEnvironmentCaseOne() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
other.setEnvironment("example");
assertEquals(false, event.equals(other));
}

@Test
void testEqualsEnvironmentCaseTwo() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setEnvironment("example");
assertEquals(false, event.equals(other));
}

@Test
void testEqualsEnvironmentCaseThree() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setEnvironment("example1");
other.setEnvironment("example2");
assertEquals(false, event.equals(other));
}

@Test
void testEqualsEnvironmentCaseFour() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setEnvironment("example");
other.setEnvironment("example");
assertEquals(true, event.equals(other));
}

// testEqualsId //

@Test
void testEqualsIdCaseOne() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
other.setId(99L);
assertEquals(false, event.equals(other));
}

@Test
void testEqualsIdCaseTwo() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setId(99L);
assertEquals(false, event.equals(other));
}

@Test
void testEqualsIdCaseThree() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setId(1L);
other.setId(2L);
assertEquals(false, event.equals(other));
}

@Test
void testEqualsIdCaseFour() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setId(99L);
other.setId(99L);
assertEquals(true, event.equals(other));
}

// testEqualsAwsId //

@Test
void testEqualsAwsIdCaseOne() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
other.setAwsId("AWS");
assertEquals(false, event.equals(other));
}

@Test
void testEqualsAwsIdCaseTwo() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setAwsId("AWS");
assertEquals(false, event.equals(other));
}

@Test
void testEqualsAwsIdCaseThree() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setAwsId("AWS1");
other.setAwsId("AWS2");
assertEquals(false, event.equals(other));
}

@Test
void testEqualsAwsIdCaseFour() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setAwsId("AWS");
other.setAwsId("AWS");
assertEquals(true, event.equals(other));
}

// testEqualsTime //

@Test
void testEqualsTimeCaseOne() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
other.setTimeOfEvent(OffsetDateTime.of(1, 1, 1, 1, 1, 1, 1, ZoneOffset.of("Z")));
assertEquals(false, event.equals(other));
}

@Test
void testEqualsTimeCaseTwo() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setTimeOfEvent(OffsetDateTime.of(1, 1, 1, 1, 1, 1, 1, ZoneOffset.of("Z")));
assertEquals(false, event.equals(other));
}

@Test
void testEqualsTimeCaseThree() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setTimeOfEvent(OffsetDateTime.of(1, 1, 1, 1, 1, 1, 1, ZoneOffset.of("Z")));
other.setTimeOfEvent(OffsetDateTime.of(9, 9, 9, 9, 9, 9, 9, ZoneOffset.of("Z")));
assertEquals(false, event.equals(other));
}

@Test
void testEqualsTimeCaseFour() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setTimeOfEvent(OffsetDateTime.of(1, 1, 1, 1, 1, 1, 1, ZoneOffset.of("Z")));
other.setTimeOfEvent(OffsetDateTime.of(1, 1, 1, 1, 1, 1, 1, ZoneOffset.of("Z")));
assertEquals(true, event.equals(other));
}

// testEqualsOrg //

@Test
void testEqualsOrgCaseOne() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
other.setOrganization("CMS");
assertEquals(false, event.equals(other));
}

@Test
void testEqualsOrgCaseTwo() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setOrganization("CMS");
assertEquals(false, event.equals(other));
}

@Test
void testEqualsOrgCaseThree() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setOrganization("CMS1");
other.setOrganization("CMS2");
assertEquals(false, event.equals(other));
}

@Test
void testEqualsOrgCaseFour() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setOrganization("CMS");
other.setOrganization("CMS");
assertEquals(true, event.equals(other));
}

// testEqualsJob //

@Test
void testEqualsJobCaseOne() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
other.setJobId("1234");
assertEquals(false, event.equals(other));
}

@Test
void testEqualsJobCaseTwo() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setJobId("1234");
assertEquals(false, event.equals(other));
}

@Test
void testEqualsJobCaseThree() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setJobId("1234");
other.setJobId("9999");
assertEquals(false, event.equals(other));
}

@Test
void testEqualsJobCaseFour() {
LoggableEvent event = new MockLoggableEvent();
LoggableEvent other = new MockLoggableEvent();
event.setJobId("1234");
other.setJobId("1234");
assertEquals(true, event.equals(other));
}

}
Loading