-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(openchallenges): improve organization service model entity unit …
…test coverage (#2536)
- Loading branch information
Showing
2 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...rks/openchallenges/organization/service/model/entity/ChallengeContributionEntityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.sagebionetworks.openchallenges.organization.service.model.entity; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ChallengeContributionEntityTest { | ||
|
||
private OrganizationEntity organization; | ||
private ChallengeContributionEntity contributor1; | ||
private ChallengeContributionEntity contributor2; | ||
private ChallengeContributionEntity contributor3; | ||
private Long entityId1 = 1L; | ||
private Long entityId2 = 2L; | ||
private String role = "role"; | ||
|
||
@BeforeEach | ||
void setup() { | ||
// Create an OrganizationEntity | ||
organization = new OrganizationEntity(); | ||
|
||
// Create different ChallengeContributionEntity using different methods | ||
contributor1 = new ChallengeContributionEntity(); | ||
contributor1.setId(entityId1); | ||
contributor1.setRole(role); | ||
contributor1.setOrganization(organization); | ||
|
||
contributor2 = new ChallengeContributionEntity(entityId1, role, organization); | ||
|
||
contributor3 = | ||
ChallengeContributionEntity.builder() | ||
.id(entityId2) | ||
.organization(organization) | ||
.role(role) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void getters_ShouldReturnExpectedValues_WhenArgumentsPassed() { | ||
// Verify the values are set when the setters are used to set them (NoArgsConstructor) | ||
Assertions.assertEquals(entityId1, contributor1.getId()); | ||
Assertions.assertEquals(organization, contributor1.getOrganization()); | ||
Assertions.assertEquals(role, contributor1.getRole()); | ||
|
||
// Verify the values are set with the ArgsConstructor | ||
Assertions.assertEquals(entityId1, contributor2.getId()); | ||
Assertions.assertEquals(organization, contributor2.getOrganization()); | ||
Assertions.assertEquals(role, contributor2.getRole()); | ||
} | ||
|
||
@Test | ||
void getters_ShouldReturnArgumentsPassed_WhenBuiltWithBuilder() { | ||
// Verify the values are set | ||
Assertions.assertEquals(entityId2, contributor3.getId()); | ||
Assertions.assertEquals(organization, contributor3.getOrganization()); | ||
Assertions.assertEquals(role, contributor3.getRole()); | ||
} | ||
|
||
@Test | ||
void shouldBeTheSameOrDifferent_WhenTwoChallengeContributionEntitiesCompared() { | ||
// Verify the generated equals() method | ||
Assertions.assertEquals(contributor1, contributor2); | ||
Assertions.assertNotEquals(contributor1, contributor3); | ||
} | ||
|
||
@Test | ||
void hashCode_ShouldBeTheSameOrDifferent_WhenTwoChallengeContributionEntitiesCompared() { | ||
// Verify the generated hashCode() method | ||
Assertions.assertEquals(contributor1.hashCode(), contributor2.hashCode()); | ||
Assertions.assertNotEquals(contributor1.hashCode(), contributor3.hashCode()); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...orks/openchallenges/organization/service/model/entity/OrganizationCategoryEntityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.sagebionetworks.openchallenges.organization.service.model.entity; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class OrganizationCategoryEntityTest { | ||
|
||
private OrganizationEntity organization; | ||
private OrganizationCategoryEntity contributor1; | ||
private OrganizationCategoryEntity contributor2; | ||
private OrganizationCategoryEntity contributor3; | ||
private Long entityId1 = 1L; | ||
private Long entityId2 = 2L; | ||
private String category = "category"; | ||
|
||
@BeforeEach | ||
void setup() { | ||
organization = new OrganizationEntity(); | ||
|
||
contributor1 = new OrganizationCategoryEntity(); | ||
contributor1.setId(entityId1); | ||
contributor1.setCategory(category); | ||
contributor1.setOrganization(organization); | ||
|
||
contributor2 = new OrganizationCategoryEntity(entityId1, category, organization); | ||
|
||
contributor3 = | ||
OrganizationCategoryEntity.builder() | ||
.id(entityId2) | ||
.organization(organization) | ||
.category(category) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void getters_ShouldReturnExpectedValues_WhenArgumentsPassed() { | ||
// Verify the values are set when the setters are used to set them (NoArgsConstructor) | ||
Assertions.assertEquals(entityId1, contributor1.getId(), "ID should match for contributor1"); | ||
Assertions.assertEquals( | ||
organization, contributor1.getOrganization(), "Organization should match for contributor1"); | ||
Assertions.assertEquals( | ||
category, contributor1.getCategory(), "Category should match for contributor1"); | ||
|
||
// Verify the values are set when set with the ArgsConstructor | ||
Assertions.assertEquals(entityId1, contributor2.getId(), "ID should match for contributor2"); | ||
Assertions.assertEquals( | ||
organization, contributor2.getOrganization(), "Organization should match for contributor2"); | ||
Assertions.assertEquals( | ||
category, contributor2.getCategory(), "Category should match for contributor2"); | ||
} | ||
|
||
@Test | ||
void shouldReturnArgumentsPassed_WhenOrganizationCategoryEntityBuiltWithClassBuilder() { | ||
// Verify the values are set | ||
Assertions.assertEquals(entityId2, contributor3.getId(), "ID should match for contributor3"); | ||
Assertions.assertEquals( | ||
organization, contributor3.getOrganization(), "Organization should match for contributor3"); | ||
Assertions.assertEquals( | ||
category, contributor3.getCategory(), "Category should match for contributor3"); | ||
} | ||
|
||
@Test | ||
void shouldReturnSameOrDifferent_WhenTwoOrganizationCategoryEntityCompared() { | ||
// Verify the generated equals() method | ||
Assertions.assertEquals(contributor1, contributor2, "Contributors 1 and 2 should be equal"); | ||
Assertions.assertNotEquals( | ||
contributor1, contributor3, "Contributors 1 and 3 should not be equal"); | ||
} | ||
|
||
@Test | ||
void hashCode_ShouldBeTheSameOrDifferent_WhenTwoOrganizationCategoryEntityCompared() { | ||
// Verify the generated hashCode() method | ||
Assertions.assertEquals( | ||
contributor1.hashCode(), | ||
contributor2.hashCode(), | ||
"Hash codes of contributors 1 and 2 should match"); | ||
Assertions.assertNotEquals( | ||
contributor1.hashCode(), | ||
contributor3.hashCode(), | ||
"Hash codes of contributors 1 and 3 should not match"); | ||
} | ||
} |