-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9010 from bencomp/overload-datasetfield
Overload DatasetField method to remove type check
- Loading branch information
Showing
2 changed files
with
83 additions
and
13 deletions.
There are no files selected for viewing
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
64 changes: 64 additions & 0 deletions
64
src/test/java/edu/harvard/iq/dataverse/DatasetFieldTest.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,64 @@ | ||
package edu.harvard.iq.dataverse; | ||
|
||
import edu.harvard.iq.dataverse.DatasetFieldType.FieldType; | ||
import edu.harvard.iq.dataverse.mocks.MocksFactory; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
|
||
class DatasetFieldTest { | ||
@Test | ||
void testCreateNewEmptyDatasetField_withEmptyTemplate() { | ||
Template template = new Template(); | ||
|
||
DatasetField field = DatasetField.createNewEmptyDatasetField(new DatasetFieldType("subject", FieldType.TEXT, false), template); | ||
assertTrue(field.getTemplate() == template); | ||
assertTrue(template.getDatasetFields().isEmpty()); | ||
} | ||
|
||
@Test | ||
void testNotEqualDatasetFields() { | ||
DatasetFieldType type1 = new DatasetFieldType("subject", FieldType.TEXT, false); | ||
Template template1 = new Template(); | ||
DatasetField field1 = DatasetField.createNewEmptyDatasetField(type1, template1); | ||
field1.setId(MocksFactory.nextId()); | ||
DatasetFieldType type2 = new DatasetFieldType("subject", FieldType.TEXT, false); | ||
Template template2 = new Template(); | ||
DatasetField field2 = DatasetField.createNewEmptyDatasetField(type2, template2); | ||
field2.setId(MocksFactory.nextId()); | ||
|
||
assertNotEquals(field1, field2); | ||
assertNotEquals(field1, template2); | ||
} | ||
|
||
@Test | ||
void testEqualDatasetFields() { | ||
DatasetField field1 = DatasetField.createNewEmptyDatasetField(new DatasetFieldType("subject", FieldType.TEXT, false), new Template()); | ||
field1.setId(100L); | ||
DatasetField field2 = DatasetField.createNewEmptyDatasetField(new DatasetFieldType("subject", FieldType.TEXT, false), new Template()); | ||
|
||
// Fields are not equal before both have IDs set | ||
assertNotEquals(field1, field2); | ||
|
||
field2.setId(100L); | ||
|
||
assertEquals(field1, field2); | ||
} | ||
|
||
@Test | ||
void testCopyDatasetFields() { | ||
DatasetField field1 = DatasetField.createNewEmptyDatasetField(new DatasetFieldType("subject", FieldType.TEXT, false), new Template()); | ||
field1.setId(100L); | ||
DatasetField field2 = field1.copy(field1.getTemplate()); | ||
|
||
assertNull(field2.getId()); | ||
// A copy of a field should not be equal | ||
assertNotEquals(field1, field2); | ||
|
||
assertEquals(field2.getDatasetFieldType(), field1.getDatasetFieldType()); | ||
} | ||
} |