-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding AppraiserTest and TestAppraiser
- Loading branch information
1 parent
6b12e3d
commit 2e8569d
Showing
2 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/entity/AppraiserTest.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,135 @@ | ||
package hirs.attestationca.persist.entity; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
/** | ||
* Unit tests for the class <code>Appraiser</code>. | ||
*/ | ||
public final class AppraiserTest { | ||
|
||
/** | ||
* Tests that an <code>Appraiser</code> can be created with a valid name. | ||
*/ | ||
@Test | ||
public void testAppraiser() { | ||
final String name = "Test Appraiser"; | ||
new TestAppraiser(name); | ||
} | ||
|
||
/** | ||
* Tests that the name is returned from <code>getName</code>. | ||
*/ | ||
@Test | ||
public void testGetName() { | ||
final String name = "Test Appraiser"; | ||
final Appraiser appraiser = new TestAppraiser(name); | ||
assertEquals(appraiser.getName(), name); | ||
} | ||
|
||
/** | ||
* Tests that the name property can be set. | ||
*/ | ||
@Test | ||
public void testSetName() { | ||
final String originalName = "Test Appraiser"; | ||
final Appraiser appraiser = new TestAppraiser(originalName); | ||
assertEquals(appraiser.getName(), originalName); | ||
final String newName = "Awesome Test Appraiser"; | ||
appraiser.setName(newName); | ||
assertEquals(appraiser.getName(), newName); | ||
} | ||
|
||
/** | ||
* Tests that x.equals(null) returns false. | ||
*/ | ||
@Test | ||
public void testEqualsNull() { | ||
final String name = "Test Appraiser"; | ||
final Appraiser appraiser = new TestAppraiser(name); | ||
assertNotEquals(null, appraiser); | ||
} | ||
|
||
/** | ||
* Tests that x.equals(x) for an appraiser. | ||
*/ | ||
@Test | ||
public void testEqualsReflexive() { | ||
final String name = "Test Appraiser"; | ||
final Appraiser appraiser = new TestAppraiser(name); | ||
assertTrue(appraiser.equals(appraiser)); | ||
} | ||
|
||
/** | ||
* Tests that x.equals(y) and y.equals(x) for an appraiser. | ||
*/ | ||
@Test | ||
public void testEqualsSymmetric() { | ||
final String name = "Test Appraiser"; | ||
final Appraiser appraiser1 = new TestAppraiser(name); | ||
final Appraiser appraiser2 = new TestAppraiser(name); | ||
assertEquals(appraiser1, appraiser2); | ||
assertEquals(appraiser2, appraiser1); | ||
} | ||
|
||
/** | ||
* Tests that x.equals(y) and y.equals(z) then x.equals(z) for an appraiser. | ||
*/ | ||
@Test | ||
public void testEqualsTransitive() { | ||
final String name = "Test Appraiser"; | ||
final Appraiser appraiser1 = new TestAppraiser(name); | ||
final Appraiser appraiser2 = new TestAppraiser(name); | ||
final Appraiser appraiser3 = new TestAppraiser(name); | ||
assertEquals(appraiser1, appraiser2); | ||
assertEquals(appraiser2, appraiser3); | ||
assertEquals(appraiser1, appraiser3); | ||
} | ||
|
||
/** | ||
* Tests that two appraisers are not equal if their names are different. | ||
*/ | ||
@Test | ||
public void testNotEquals() { | ||
final String name1 = "Test Appraiser"; | ||
final String name2 = "Other Appraiser"; | ||
final Appraiser appraiser1 = new TestAppraiser(name1); | ||
final Appraiser appraiser2 = new TestAppraiser(name2); | ||
assertNotEquals(appraiser1, appraiser2); | ||
assertNotEquals(appraiser2, appraiser1); | ||
} | ||
|
||
/** | ||
* Tests that if two appraisers are equal that their hash codes are equal. | ||
*/ | ||
@Test | ||
public void testHashCodeEquals() { | ||
final String name = "Test Appraiser"; | ||
final Appraiser appraiser1 = new TestAppraiser(name); | ||
final Appraiser appraiser2 = new TestAppraiser(name); | ||
assertEquals(appraiser1, appraiser2); | ||
assertEquals(appraiser2, appraiser1); | ||
assertEquals(appraiser1.hashCode(), appraiser2.hashCode()); | ||
assertEquals(appraiser2.hashCode(), appraiser1.hashCode()); | ||
} | ||
|
||
/** | ||
* Tests that if two appraisers are not equal that their hash codes are not equal. | ||
*/ | ||
@Test | ||
public void testHashCodeNotEquals() { | ||
final String name1 = "Test Appraiser"; | ||
final String name2 = "Other Appraiser"; | ||
final Appraiser appraiser1 = new TestAppraiser(name1); | ||
final Appraiser appraiser2 = new TestAppraiser(name2); | ||
assertNotEquals(appraiser1, appraiser2); | ||
assertNotEquals(appraiser2, appraiser1); | ||
assertNotEquals(appraiser1.hashCode(), appraiser2.hashCode()); | ||
assertNotEquals(appraiser2.hashCode(), appraiser1.hashCode()); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/entity/TestAppraiser.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,26 @@ | ||
package hirs.attestationca.persist.entity; | ||
|
||
import jakarta.persistence.Entity; | ||
|
||
/** | ||
* Test class for the <code>Appraiser</code> abstract base class. | ||
*/ | ||
@Entity | ||
public class TestAppraiser extends Appraiser { | ||
|
||
/** | ||
* Creates a new <code>TestAppraiser</code>. | ||
* | ||
* @param name name | ||
*/ | ||
public TestAppraiser(final String name) { | ||
super(name); | ||
} | ||
|
||
/** | ||
* Default constructor necessary for Hibernate. | ||
*/ | ||
protected TestAppraiser() { | ||
/* do nothing */ | ||
} | ||
} |