Changed List return type to ImmutableList in Wikidata schema package classes (#3070)

* replaced ImmutableList to unmodifiableList

* added test cases to check unmodifiable Lists

* improved test cases
This commit is contained in:
Ekta Mishra 2020-08-13 13:29:54 +05:30 committed by GitHub
parent 0ce5c5de13
commit f50efb3699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 56 additions and 7 deletions

View File

@ -96,12 +96,12 @@ public class WbItemDocumentExpr implements WbExpression<ItemUpdate> {
@JsonProperty("nameDescs")
public List<WbNameDescExpr> getNameDescs() {
return nameDescs;
return Collections.unmodifiableList(nameDescs);
}
@JsonProperty("statementGroups")
public List<WbStatementGroupExpr> getStatementGroups() {
return statementGroups;
return Collections.unmodifiableList(statementGroups);
}
@Override

View File

@ -24,6 +24,7 @@
package org.openrefine.wikidata.schema;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang.Validate;
@ -77,7 +78,7 @@ public class WbReferenceExpr implements WbExpression<Reference> {
@JsonProperty("snaks")
public List<WbSnakExpr> getSnaks() {
return snakExprs;
return Collections.unmodifiableList(snakExprs);
}
@Override

View File

@ -134,12 +134,12 @@ public class WbStatementExpr {
@JsonProperty("qualifiers")
public List<WbSnakExpr> getQualifiers() {
return qualifierExprs;
return Collections.unmodifiableList(qualifierExprs);
}
@JsonProperty("references")
public List<WbReferenceExpr> getReferences() {
return referenceExprs;
return Collections.unmodifiableList(referenceExprs);
}
@Override

View File

@ -24,6 +24,7 @@
package org.openrefine.wikidata.schema;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jsoup.helper.Validate;
@ -79,7 +80,7 @@ public class WbStatementGroupExpr {
@JsonProperty("statements")
public List<WbStatementExpr> getStatements() {
return statementExprs;
return Collections.unmodifiableList(statementExprs);
}
@Override

View File

@ -25,6 +25,7 @@ package org.openrefine.wikidata.schema;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.openrefine.wikidata.qa.QAWarningStore;
@ -90,7 +91,7 @@ public class WikibaseSchema implements OverlayModel {
*/
@JsonIgnore
public List<WbItemDocumentExpr> getItemDocumentExpressions() {
return itemDocumentExprs;
return Collections.unmodifiableList(itemDocumentExprs);
}
public void setItemDocumentExpressions(List<WbItemDocumentExpr> exprs) {

View File

@ -24,10 +24,12 @@
package org.openrefine.wikidata.schema;
import java.util.Collections;
import java.util.List;
import org.openrefine.wikidata.testing.JacksonSerializationTest;
import org.openrefine.wikidata.updates.ItemUpdate;
import org.openrefine.wikidata.updates.ItemUpdateBuilder;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
@ -89,4 +91,14 @@ public class WbItemDocumentExprTest extends WbExpressionTest<ItemUpdate> {
public void testSerialize() {
JacksonSerializationTest.canonicalSerialization(WbItemDocumentExpr.class, expr, jsonRepresentation);
}
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testUnmodifiableNameDescsList() {
expr.getNameDescs().clear();
}
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testUnmodifiableStatementGroupsList() {
expr.getStatementGroups().clear();
}
}

View File

@ -25,8 +25,10 @@ package org.openrefine.wikidata.schema;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.openrefine.wikidata.testing.JacksonSerializationTest;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.Reference;
@ -77,4 +79,9 @@ public class WbReferenceExprTest extends WbExpressionTest<Reference> {
throws JsonProcessingException {
JacksonSerializationTest.canonicalSerialization(WbReferenceExpr.class, expr, jsonRepresentation);
}
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testUnmodifiableList() {
expr.getSnaks().clear();
}
}

View File

@ -23,11 +23,13 @@
******************************************************************************/
package org.openrefine.wikidata.schema;
import org.testng.Assert;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.openrefine.wikidata.testing.JacksonSerializationTest;
@ -155,4 +157,14 @@ public class WbStatementExprTest extends WbExpressionTest<Statement> {
public void testSerialize() {
JacksonSerializationTest.canonicalSerialization(WbStatementExpr.class, statementExpr, jsonRepresentation);
}
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testUnmodifiableQualifiersList() {
statementExpr.getQualifiers().clear();
}
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testUnmodifiableReferencesList() {
statementExpr.getReferences().clear();
}
}

View File

@ -24,9 +24,11 @@
package org.openrefine.wikidata.schema;
import java.util.Collections;
import java.util.List;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.openrefine.wikidata.testing.JacksonSerializationTest;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
@ -90,4 +92,9 @@ public class WbStatementGroupExprTest extends WbExpressionTest<StatementGroup> {
throws JsonProcessingException {
JacksonSerializationTest.canonicalSerialization(WbStatementGroupExpr.class, expr, jsonRepresentation);
}
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testUnmodifiableList() {
expr.getStatements().clear();
}
}

View File

@ -23,6 +23,7 @@
******************************************************************************/
package org.openrefine.wikidata.schema;
import org.testng.Assert;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
@ -157,4 +158,11 @@ public class WikibaseSchemaTest extends WikidataRefineTest {
expected.add(update1);
assertEquals(expected, updates);
}
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testUnmodifiableList() throws IOException {
String serialized = TestingData.jsonFromFile("schema/inception.json");
WikibaseSchema schema = WikibaseSchema.reconstruct(serialized);
schema.getItemDocumentExpressions().clear();
}
}