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")
|
@JsonProperty("nameDescs")
|
||||||
public List<WbNameDescExpr> getNameDescs() {
|
public List<WbNameDescExpr> getNameDescs() {
|
||||||
return nameDescs;
|
return Collections.unmodifiableList(nameDescs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty("statementGroups")
|
@JsonProperty("statementGroups")
|
||||||
public List<WbStatementGroupExpr> getStatementGroups() {
|
public List<WbStatementGroupExpr> getStatementGroups() {
|
||||||
return statementGroups;
|
return Collections.unmodifiableList(statementGroups);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
@ -77,7 +78,7 @@ public class WbReferenceExpr implements WbExpression<Reference> {
|
|||||||
|
|
||||||
@JsonProperty("snaks")
|
@JsonProperty("snaks")
|
||||||
public List<WbSnakExpr> getSnaks() {
|
public List<WbSnakExpr> getSnaks() {
|
||||||
return snakExprs;
|
return Collections.unmodifiableList(snakExprs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -134,12 +134,12 @@ public class WbStatementExpr {
|
|||||||
|
|
||||||
@JsonProperty("qualifiers")
|
@JsonProperty("qualifiers")
|
||||||
public List<WbSnakExpr> getQualifiers() {
|
public List<WbSnakExpr> getQualifiers() {
|
||||||
return qualifierExprs;
|
return Collections.unmodifiableList(qualifierExprs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty("references")
|
@JsonProperty("references")
|
||||||
public List<WbReferenceExpr> getReferences() {
|
public List<WbReferenceExpr> getReferences() {
|
||||||
return referenceExprs;
|
return Collections.unmodifiableList(referenceExprs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jsoup.helper.Validate;
|
import org.jsoup.helper.Validate;
|
||||||
@ -79,7 +80,7 @@ public class WbStatementGroupExpr {
|
|||||||
|
|
||||||
@JsonProperty("statements")
|
@JsonProperty("statements")
|
||||||
public List<WbStatementExpr> getStatements() {
|
public List<WbStatementExpr> getStatements() {
|
||||||
return statementExprs;
|
return Collections.unmodifiableList(statementExprs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,6 +25,7 @@ package org.openrefine.wikidata.schema;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.openrefine.wikidata.qa.QAWarningStore;
|
import org.openrefine.wikidata.qa.QAWarningStore;
|
||||||
@ -90,7 +91,7 @@ public class WikibaseSchema implements OverlayModel {
|
|||||||
*/
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public List<WbItemDocumentExpr> getItemDocumentExpressions() {
|
public List<WbItemDocumentExpr> getItemDocumentExpressions() {
|
||||||
return itemDocumentExprs;
|
return Collections.unmodifiableList(itemDocumentExprs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItemDocumentExpressions(List<WbItemDocumentExpr> exprs) {
|
public void setItemDocumentExpressions(List<WbItemDocumentExpr> exprs) {
|
||||||
|
@ -24,10 +24,12 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.openrefine.wikidata.testing.JacksonSerializationTest;
|
import org.openrefine.wikidata.testing.JacksonSerializationTest;
|
||||||
import org.openrefine.wikidata.updates.ItemUpdate;
|
import org.openrefine.wikidata.updates.ItemUpdate;
|
||||||
import org.openrefine.wikidata.updates.ItemUpdateBuilder;
|
import org.openrefine.wikidata.updates.ItemUpdateBuilder;
|
||||||
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||||
@ -89,4 +91,14 @@ public class WbItemDocumentExprTest extends WbExpressionTest<ItemUpdate> {
|
|||||||
public void testSerialize() {
|
public void testSerialize() {
|
||||||
JacksonSerializationTest.canonicalSerialization(WbItemDocumentExpr.class, expr, jsonRepresentation);
|
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.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.openrefine.wikidata.testing.JacksonSerializationTest;
|
import org.openrefine.wikidata.testing.JacksonSerializationTest;
|
||||||
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.Reference;
|
import org.wikidata.wdtk.datamodel.interfaces.Reference;
|
||||||
@ -77,4 +79,9 @@ public class WbReferenceExprTest extends WbExpressionTest<Reference> {
|
|||||||
throws JsonProcessingException {
|
throws JsonProcessingException {
|
||||||
JacksonSerializationTest.canonicalSerialization(WbReferenceExpr.class, expr, jsonRepresentation);
|
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;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.testng.Assert;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.openrefine.wikidata.testing.JacksonSerializationTest;
|
import org.openrefine.wikidata.testing.JacksonSerializationTest;
|
||||||
@ -155,4 +157,14 @@ public class WbStatementExprTest extends WbExpressionTest<Statement> {
|
|||||||
public void testSerialize() {
|
public void testSerialize() {
|
||||||
JacksonSerializationTest.canonicalSerialization(WbStatementExpr.class, statementExpr, jsonRepresentation);
|
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;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.openrefine.wikidata.testing.JacksonSerializationTest;
|
import org.openrefine.wikidata.testing.JacksonSerializationTest;
|
||||||
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||||
@ -90,4 +92,9 @@ public class WbStatementGroupExprTest extends WbExpressionTest<StatementGroup> {
|
|||||||
throws JsonProcessingException {
|
throws JsonProcessingException {
|
||||||
JacksonSerializationTest.canonicalSerialization(WbStatementGroupExpr.class, expr, jsonRepresentation);
|
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;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.testng.Assert;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -157,4 +158,11 @@ public class WikibaseSchemaTest extends WikidataRefineTest {
|
|||||||
expected.add(update1);
|
expected.add(update1);
|
||||||
assertEquals(expected, updates);
|
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