-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
New Tests for ProjectMembershipEntity #245
Open
F4c3hugg3r
wants to merge
1
commit into
remsfal:main
Choose a base branch
from
F4c3hugg3r:dev-ProjectMembershipEntityTest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
remsfal-service/src/test/java/de/remsfal/service/entity/ProjectMembershipEntityTest.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,99 @@ | ||
package de.remsfal.service.entity; | ||
|
||
import de.remsfal.core.model.ProjectMemberModel; | ||
import de.remsfal.service.entity.dto.ProjectEntity; | ||
import de.remsfal.service.entity.dto.ProjectMembershipEntity; | ||
import de.remsfal.service.entity.dto.UserEntity; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@QuarkusTest | ||
public class ProjectMembershipEntityTest { | ||
|
||
private ProjectMembershipEntity entity1; | ||
private ProjectMembershipEntity entity2; | ||
private ProjectEntity project1; | ||
private UserEntity user1; | ||
private UserEntity user2; | ||
|
||
|
||
@BeforeEach | ||
//entity1 is equal to entity2 | ||
public void setUp () { | ||
project1 = new ProjectEntity(); | ||
user1 = new UserEntity(); | ||
user2 = new UserEntity(); | ||
project1.setId("1"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, use realistic values provided by de.remsfal.service.TestData |
||
user1.setId("1"); | ||
user2.setId("2"); | ||
|
||
entity1 = new ProjectMembershipEntity(); | ||
entity1.setProject(project1); | ||
entity1.setUser(user1); | ||
entity1.setRole(ProjectMemberModel.UserRole.MANAGER); | ||
|
||
entity2 = new ProjectMembershipEntity(); | ||
entity2.setProject(project1); | ||
entity2.setUser(user1); | ||
entity2.setRole(ProjectMemberModel.UserRole.MANAGER); | ||
} | ||
|
||
//Tests if equality of ProjectMember objects is based on equality of project, user & role | ||
@Test | ||
@DisplayName("Tests two equal objects") | ||
public void testEqualsSameValues () { | ||
assertEquals(entity1, entity2); | ||
} | ||
|
||
@Test | ||
@DisplayName("Tests two unequal objects (different project)") | ||
public void testEqualsDifferentProjects () { | ||
ProjectEntity project2 = new ProjectEntity(); | ||
project2.setId("2"); | ||
entity2.setProject(project2); | ||
|
||
assertNotEquals(entity1, entity2); | ||
} | ||
|
||
@Test | ||
@DisplayName("Tests two unequal objects (different user)") | ||
public void testEqualsDifferentUsers () { | ||
entity2.setUser(user2); | ||
|
||
assertNotEquals(entity1, entity2); | ||
} | ||
|
||
@Test | ||
@DisplayName("Test two unequal objects (different role)") | ||
public void testEqualsDifferentRoles () { | ||
entity2.setRole(ProjectMemberModel.UserRole.LESSOR); | ||
|
||
assertNotEquals(entity1, entity2); | ||
} | ||
|
||
@Test | ||
@DisplayName("Tests if the correct String is being generated") | ||
public void testToString() { | ||
ProjectMembershipEntity entity3 = new ProjectMembershipEntity(); | ||
entity3.setProject(project1); | ||
entity3.setUser(user2); | ||
entity3.setRole(ProjectMemberModel.UserRole.LESSOR); | ||
|
||
user2.setEmail("blabla"); | ||
user2.setFirstName("Alex"); | ||
user2.setLastName("Muster"); | ||
|
||
String entity1String = "ProjectMembershipEntity: {id=2, email=blabla, name=Alex Muster, role=LESSOR}"; | ||
assertEquals(entity1String, entity3.toString()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Tests if setId() throws IllegalArgumentException") | ||
public void testSetId () { | ||
assertThrows(IllegalArgumentException.class, () -> entity1.setId("test")); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use star imports