-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed NPE when underlying data was null, added few tests
- Loading branch information
Showing
8 changed files
with
267 additions
and
4 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
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
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
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
75 changes: 75 additions & 0 deletions
75
.../test/java/uk/gov/nationalarchives/droid/export/template/ConstantStringColumnDefTest.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,75 @@ | ||
/* | ||
* Copyright (c) 2016, The National Archives <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of the The National Archives nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package uk.gov.nationalarchives.droid.export.template; | ||
|
||
import org.junit.Test; | ||
import uk.gov.nationalarchives.droid.export.interfaces.ExportTemplateColumnDef; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class ConstantStringColumnDefTest { | ||
@Test | ||
public void should_operate_on_null_value_and_return_empty_string() { | ||
ConstantStringColumnDef def = new ConstantStringColumnDef("English (UK)", "Language"); | ||
assertEquals("", def.getOperatedValue(null)); | ||
} | ||
|
||
@Test | ||
public void should_return_input_as_it_is_when_asked_for_operated_value() { | ||
ConstantStringColumnDef def = new ConstantStringColumnDef("English (UK)", "Language"); | ||
assertEquals("FoRMat", def.getOperatedValue("FoRMat")); | ||
} | ||
|
||
@Test | ||
public void should_return_header_label_as_set_when_defining_the_column_definition() { | ||
ConstantStringColumnDef def = new ConstantStringColumnDef("English (UK)", "Language"); | ||
assertEquals("Language", def.getHeaderLabel()); | ||
} | ||
@Test | ||
public void should_throw_exception_when_asking_for_original_column_name() { | ||
ConstantStringColumnDef def = new ConstantStringColumnDef("English (UK)", "Language"); | ||
RuntimeException ex = assertThrows(RuntimeException.class, () -> def.getOriginalColumnName()); | ||
assertEquals("Constant String Columns do not have an associated original column name", ex.getMessage()); | ||
} | ||
|
||
@Test | ||
public void should_return_data_as_set_in_the_definition() { | ||
ConstantStringColumnDef def = new ConstantStringColumnDef("English (UK)", "Language"); | ||
assertEquals("English (UK)", def.getDataValue()); | ||
} | ||
|
||
@Test | ||
public void should_return_column_type_as_data_modifier_column_def() { | ||
ConstantStringColumnDef def = new ConstantStringColumnDef("English (UK)", "Language"); | ||
assertEquals(ExportTemplateColumnDef.ColumnType.ConstantString, def.getColumnType()); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...rc/test/java/uk/gov/nationalarchives/droid/export/template/DataModifierColumnDefTest.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,70 @@ | ||
/* | ||
* Copyright (c) 2016, The National Archives <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of the The National Archives nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package uk.gov.nationalarchives.droid.export.template; | ||
|
||
import org.junit.Test; | ||
import uk.gov.nationalarchives.droid.export.interfaces.ExportTemplateColumnDef; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class DataModifierColumnDefTest { | ||
@Test | ||
public void should_operate_on_null_value_and_return_empty_string() { | ||
ProfileResourceNodeColumnDef innerDef = mock(ProfileResourceNodeColumnDef.class); | ||
DataModifierColumnDef def = new DataModifierColumnDef(innerDef, ExportTemplateColumnDef.DataModification.LCASE); | ||
assertEquals("", def.getOperatedValue(null)); | ||
} | ||
|
||
@Test | ||
public void should_return_header_label_as_set_on_the_inner_profile_def() { | ||
ProfileResourceNodeColumnDef innerDef = mock(ProfileResourceNodeColumnDef.class); | ||
when(innerDef.getHeaderLabel()).thenReturn("InnerHeader"); | ||
DataModifierColumnDef def = new DataModifierColumnDef(innerDef, ExportTemplateColumnDef.DataModification.LCASE); | ||
assertEquals("InnerHeader", def.getHeaderLabel()); | ||
} | ||
@Test | ||
public void should_return_original_column_name_as_set_on_the_inner_profile_def() { | ||
ProfileResourceNodeColumnDef innerDef = mock(ProfileResourceNodeColumnDef.class); | ||
when(innerDef.getOriginalColumnName()).thenReturn("FORMAT_NAME"); | ||
DataModifierColumnDef def = new DataModifierColumnDef(innerDef, ExportTemplateColumnDef.DataModification.LCASE); | ||
assertEquals("FORMAT_NAME", def.getOriginalColumnName()); | ||
} | ||
|
||
@Test | ||
public void should_return_column_type_as_data_modifier_column_def() { | ||
ProfileResourceNodeColumnDef innerDef = mock(ProfileResourceNodeColumnDef.class); | ||
DataModifierColumnDef def = new DataModifierColumnDef(innerDef, ExportTemplateColumnDef.DataModification.LCASE); | ||
assertEquals(ExportTemplateColumnDef.ColumnType.DataModifier, def.getColumnType()); | ||
} | ||
} |
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
76 changes: 76 additions & 0 deletions
76
.../java/uk/gov/nationalarchives/droid/export/template/ProfileResourceNodeColumnDefTest.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,76 @@ | ||
/* | ||
* Copyright (c) 2016, The National Archives <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of the The National Archives nor the | ||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package uk.gov.nationalarchives.droid.export.template; | ||
|
||
import org.junit.Test; | ||
import uk.gov.nationalarchives.droid.export.interfaces.ExportTemplateColumnDef; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
public class ProfileResourceNodeColumnDefTest { | ||
@Test | ||
public void should_operate_on_null_value_and_return_empty_string() { | ||
ProfileResourceNodeColumnDef def = new ProfileResourceNodeColumnDef("FORMAT_NAME", "Format"); | ||
assertEquals("", def.getOperatedValue(null)); | ||
} | ||
|
||
@Test | ||
public void should_return_input_as_it_is_when_asked_for_operated_value() { | ||
ProfileResourceNodeColumnDef def = new ProfileResourceNodeColumnDef("FORMAT_NAME", "Format"); | ||
assertEquals("FoRMat", def.getOperatedValue("FoRMat")); | ||
} | ||
|
||
@Test | ||
public void should_return_header_label_as_set_when_defining_the_column_definition() { | ||
ProfileResourceNodeColumnDef def = new ProfileResourceNodeColumnDef("FORMAT_NAME", "Format"); | ||
assertEquals("Format", def.getHeaderLabel()); | ||
} | ||
@Test | ||
public void should_return_original_column_name_as_set_when_defining_the_column_definition() { | ||
ProfileResourceNodeColumnDef def = new ProfileResourceNodeColumnDef("FORMAT_NAME", "Format"); | ||
assertEquals("FORMAT_NAME", def.getOriginalColumnName()); | ||
} | ||
|
||
@Test | ||
public void should_throw_exception_when_asking_for_data_from_the_definition() { | ||
ProfileResourceNodeColumnDef def = new ProfileResourceNodeColumnDef("FORMAT_NAME", "Format"); | ||
RuntimeException ex = assertThrows(RuntimeException.class, () -> def.getDataValue()); | ||
assertEquals("Profile resource node column uses data from the profile results", ex.getMessage()); | ||
} | ||
|
||
@Test | ||
public void should_return_column_type_as_data_modifier_column_def() { | ||
ProfileResourceNodeColumnDef def = new ProfileResourceNodeColumnDef("FORMAT_NAME", "Format"); | ||
assertEquals(ExportTemplateColumnDef.ColumnType.ProfileResourceNode, def.getColumnType()); | ||
} | ||
} |