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:
parent
0ce5c5de13
commit
f50efb3699
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user