Skip to content

Commit 6f56a55

Browse files
committed
ont-api: cleanup tests: remove unused methods/annotations reformat code, fix potential errors, etc
1 parent 6149be2 commit 6f56a55

File tree

202 files changed

+947
-3403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+947
-3403
lines changed

src/test/java/com/github/owlcs/ontapi/tests/TestFactory.java

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* The collection of test data for testing inputs.
3232
* Created by @ssz on 22.08.2019.
3333
*/
34+
@SuppressWarnings("rawtypes")
3435
public class TestFactory {
3536

3637
public static List<Data> getObjects() {

src/test/java/com/github/owlcs/ontapi/tests/internal/AxiomPropertiesTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private static <X extends OWLAxiom> void testAxiom(List<TestFactory.AxiomData> d
171171
}
172172
}
173173

174-
@SuppressWarnings("unchecked")
174+
@SuppressWarnings({"unchecked", "rawtypes"})
175175
@SafeVarargs
176176
private static <X extends OWLNaryAxiom> void testSplitNaryAxioms(List<TestFactory.AxiomData> data,
177177
Function<X, Object>... properties) {

src/test/java/com/github/owlcs/ontapi/tests/internal/CommonAxiomsTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ public static List<AxiomData> getData() {
7575
);
7676
}
7777

78-
public static List<AxiomData> getAxiomData(AxiomType... types) {
78+
public static List<AxiomData> getAxiomData(AxiomType<?>... types) {
7979
return getObjects().stream().filter(Data::isAxiom)
8080
.map(x -> (AxiomData) x)
8181
.filter(x -> isOneOf(x, types))
8282
.collect(Collectors.toList());
8383
}
8484

85-
private static boolean isOneOf(AxiomData o, AxiomType... types) {
86-
AxiomType res = o.getType();
87-
for (AxiomType t : types) {
85+
private static boolean isOneOf(AxiomData o, AxiomType<?>... types) {
86+
AxiomType<?> res = o.getType();
87+
for (AxiomType<?> t : types) {
8888
if (res.equals(t)) return true;
8989
}
9090
return false;

src/test/java/com/github/owlcs/ontapi/tests/internal/ContentTestBase.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
package com.github.owlcs.ontapi.tests.internal;
1616

17-
import org.junit.Assert;
18-
import org.semanticweb.owlapi.model.OWLObject;
1917
import com.github.owlcs.ontapi.internal.InternalCache;
2018
import com.github.owlcs.ontapi.internal.objects.WithContent;
19+
import org.junit.Assert;
20+
import org.semanticweb.owlapi.model.OWLObject;
2121

2222
import java.lang.reflect.Field;
2323
import java.util.Arrays;
@@ -40,6 +40,7 @@ void testContent(OWLObject sample, OWLObject test) {
4040
testInternalCacheReset(sample, test);
4141
}
4242

43+
@SuppressWarnings("rawtypes")
4344
private void testInternalCacheReset(OWLObject sample, OWLObject instance) {
4445
Assert.assertTrue(instance instanceof WithContent);
4546
WithContent wc = (WithContent) instance;
@@ -54,15 +55,15 @@ private void testInternalCacheReset(OWLObject sample, OWLObject instance) {
5455
testComponents(sample, instance);
5556
}
5657

57-
private static InternalCache.Loading getContentCache(OWLObject inst) {
58+
private static InternalCache.Loading<?, ?> getContentCache(OWLObject inst) {
5859
return findDeclaredField(inst, "content");
5960
}
6061

6162
@SuppressWarnings({"unchecked", "SameParameterValue"})
6263
private static <X> X findDeclaredField(Object inst, String name) {
6364
AssertionError error = new AssertionError("Can't find field '" + name + "'");
64-
Class type = inst.getClass();
65-
Set<Class> seen = new HashSet<>();
65+
Class<?> type = inst.getClass();
66+
Set<Class<?>> seen = new HashSet<>();
6667
while (type != null) {
6768
try {
6869
Field[] fields = type.getDeclaredFields();

src/test/java/com/github/owlcs/ontapi/tests/internal/ModelObjectTest.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ public class ModelObjectTest {
3737
@Test
3838
public void testObjectAsSomeValuesFrom() {
3939
OWLDataFactory df = ObjectFactoryTestBase.ONT_DATA_FACTORY;
40-
OWLHasValueRestriction in = df.getOWLObjectHasValue(df.getOWLObjectProperty("P"), df.getOWLNamedIndividual("I"));
40+
OWLObjectHasValue in = df.getOWLObjectHasValue(df.getOWLObjectProperty("P"), df.getOWLNamedIndividual("I"));
4141
testAsSomeValuesFrom(in);
4242
}
4343

4444
@Test
4545
public void testDataAsSomeValuesFrom() {
4646
OWLDataFactory df = ObjectFactoryTestBase.ONT_DATA_FACTORY;
47-
OWLHasValueRestriction in = df.getOWLDataHasValue(df.getOWLDataProperty("P"), df.getOWLLiteral("I"));
47+
OWLDataHasValue in = df.getOWLDataHasValue(df.getOWLDataProperty("P"), df.getOWLLiteral("I"));
4848
testAsSomeValuesFrom(in);
4949
}
5050

@@ -290,13 +290,13 @@ public void testSWRLRuleEraseModelMethods() {
290290
}
291291

292292
@SuppressWarnings("unchecked")
293-
private <X extends OWLNaryAxiom & OWLSubClassOfAxiomSetShortCut> void testSubClassShortCutNaryAxiom(X expected) {
293+
private <X extends OWLNaryAxiom<?> & OWLSubClassOfAxiomSetShortCut> void testSubClassShortCutNaryAxiom(X expected) {
294294
X actual = testNaryAxiom(expected);
295295
testNarySplitMethod(expected, actual, x -> ((X) x).asOWLSubClassOfAxioms());
296296
}
297297

298298
@SuppressWarnings("unchecked")
299-
private <X extends OWLNaryAxiom> X testNaryAxiom(X expected) {
299+
private <X extends OWLNaryAxiom<?>> X testNaryAxiom(X expected) {
300300
Collection<? extends OWLAxiom> res = SplitNaryAxiomsTest.createONTAxioms(OntManagers.createONT(), expected);
301301
Assert.assertEquals(1, res.size());
302302
X actual = (X) res.iterator().next();
@@ -308,9 +308,9 @@ private <X extends OWLNaryAxiom> X testNaryAxiom(X expected) {
308308
return actual;
309309
}
310310

311-
private void testNarySplitMethod(OWLNaryAxiom expected,
312-
OWLNaryAxiom actual,
313-
Function<OWLNaryAxiom, Collection<? extends OWLAxiom>> get) {
311+
private void testNarySplitMethod(OWLNaryAxiom<?> expected,
312+
OWLNaryAxiom<?> actual,
313+
Function<OWLNaryAxiom<?>, Collection<? extends OWLAxiom>> get) {
314314
Collection<? extends OWLAxiom> expectedAxioms = get.apply(expected);
315315
Collection<? extends OWLAxiom> actualAxioms = get.apply(actual);
316316
Assert.assertEquals(expectedAxioms, actualAxioms);
@@ -350,8 +350,8 @@ private static <X extends OWLAxiom> void testUnaryPropAxiom(Function<OWLDataFact
350350
}
351351
}
352352

353-
private void testAsSomeValuesFrom(OWLHasValueRestriction in) {
354-
OWLHasValueRestriction res = (OWLHasValueRestriction) ClassExpressionTest.createONTObject(in);
353+
private void testAsSomeValuesFrom(OWLHasValueRestriction<?> in) {
354+
OWLHasValueRestriction<?> res = (OWLHasValueRestriction<?>) ClassExpressionTest.createONTObject(in);
355355
Assert.assertTrue(res instanceof ModelObject);
356356
OWLClassExpression c = res.asSomeValuesFrom();
357357
ObjectFactoryTestBase.testObjectHasNoModelReference(c);

src/test/java/com/github/owlcs/ontapi/tests/internal/NaryAxiomsTestBase.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ class NaryAxiomsTestBase extends CommonAxiomsTest {
2929
super(data);
3030
}
3131

32-
@SuppressWarnings("unchecked")
3332
@Override
3433
void testEraseModel(OWLObject sample, OWLObject actual) {
3534
super.testEraseModel(sample, actual);
3635

37-
OWLNaryAxiom owl = (OWLNaryAxiom) sample;
38-
OWLNaryAxiom ont = (OWLNaryAxiom) actual;
36+
OWLNaryAxiom<?> owl = (OWLNaryAxiom<?>) sample;
37+
OWLNaryAxiom<?> ont = (OWLNaryAxiom<?>) actual;
3938

4039
LOGGER.debug("Test asPairwiseAxioms for '{}'", data);
4140
Collection<? extends OWLObject> expectedPairwise = owl.asPairwiseAxioms();

src/test/java/com/github/owlcs/ontapi/tests/internal/ONTObjectMergeTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public static Data[] getData() {
6161
return Data.values();
6262
}
6363

64-
private static <ONT extends OntObject, OWL extends OWLNaryAxiom> void test(BiFunction<OntGraphModel, String, ONT> addDeclaration,
65-
BiConsumer<ONT, ONT> addAxioms,
66-
int initModelSize,
67-
AxiomType<OWL> type) {
64+
private static <ONT extends OntObject, OWL extends OWLNaryAxiom<?>> void test(BiFunction<OntGraphModel, String, ONT> addDeclaration,
65+
BiConsumer<ONT, ONT> addAxioms,
66+
int initModelSize,
67+
AxiomType<OWL> type) {
6868
test(addDeclaration, addAxioms, initModelSize, type, 3, 3);
6969
}
7070

@@ -256,7 +256,7 @@ void doTest() {
256256
OWLAxiom a2 = o.axioms(AxiomType.NEGATIVE_OBJECT_PROPERTY_ASSERTION).filter(OWLAxiom::isAnnotated)
257257
.findFirst().orElseThrow(AssertionError::new);
258258
// 4 from OntNPA + 3 declarations
259-
Assert.assertEquals(7, ((ONTObject) a1).triples().count());
259+
Assert.assertEquals(7, ((ONTObject<?>) a1).triples().count());
260260

261261
o.remove(a2);
262262
Assert.assertEquals(9, g.size());
@@ -509,8 +509,8 @@ void doTest() {
509509
void doTest() {
510510
test(g -> {
511511
g.setNsPrefix("s", SWRL.NS);
512-
OntSWRL.Atom a1 = g.createClassSWRLAtom(g.createOntClass("X"), g.createSWRLVariable("x"));
513-
OntSWRL.Atom a2 = g.createClassSWRLAtom(g.createOntClass("X"), g.createSWRLVariable("x"));
512+
OntSWRL.Atom<?> a1 = g.createClassSWRLAtom(g.createOntClass("X"), g.createSWRLVariable("x"));
513+
OntSWRL.Atom<?> a2 = g.createClassSWRLAtom(g.createOntClass("X"), g.createSWRLVariable("x"));
514514
g.createSWRLImp(Arrays.asList(a1, a1), Collections.emptyList());
515515
g.createSWRLImp(Arrays.asList(a1, a2), Collections.emptyList());
516516
}, 27, AxiomType.SWRL_RULE, 2, 2);

src/test/java/com/github/owlcs/ontapi/tests/internal/ObjectFactoryTestBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void testCompare(OWLObject expected, OWLObject actual) {
104104

105105
void testEraseModel(OWLObject sample, OWLObject actual) {
106106
LOGGER.debug("Test erase model for '{}'", data);
107-
OWLObject factoryObject = ((ModelObject) actual).eraseModel();
107+
OWLObject factoryObject = ((ModelObject<?>) actual).eraseModel();
108108
Assert.assertEquals(sample, factoryObject);
109109
testObjectHasNoModelReference(factoryObject);
110110
}

src/test/java/com/github/owlcs/ontapi/tests/internal/ResourceNaryAxiomsTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ public static List<AxiomData> getData() {
4545
);
4646
}
4747

48-
@SuppressWarnings("unchecked")
4948
@Test
5049
public void testONTObject() {
51-
OWLNaryAxiom owl = (OWLNaryAxiom) data.create(OWL_DATA_FACTORY);
50+
OWLNaryAxiom<?> owl = (OWLNaryAxiom<?>) data.create(OWL_DATA_FACTORY);
5251
LOGGER.debug("Test: '{}'", owl);
53-
OWLNaryAxiom ont = (OWLNaryAxiom) data.create(ONT_DATA_FACTORY);
52+
OWLNaryAxiom<?> ont = (OWLNaryAxiom<?>) data.create(ONT_DATA_FACTORY);
5453

5554
Assert.assertTrue(isONT(ont));
5655
Assert.assertTrue(isOWL(owl));

src/test/java/com/github/owlcs/ontapi/tests/internal/SplitNaryAxiomsTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,11 @@ static Collection<? extends OWLAxiom> createONTAxioms(OntologyManager m, OWLAxio
6565
return res;
6666
}
6767

68-
@SuppressWarnings("unchecked")
6968
@Test
7069
public void testONTObject() {
71-
OWLNaryAxiom owl = (OWLNaryAxiom) data.create(OWL_DATA_FACTORY);
70+
OWLNaryAxiom<?> owl = (OWLNaryAxiom<?>) data.create(OWL_DATA_FACTORY);
7271
LOGGER.debug("Test: '{}'", owl);
73-
OWLNaryAxiom ont = (OWLNaryAxiom) data.create(ONT_DATA_FACTORY);
72+
OWLNaryAxiom<?> ont = (OWLNaryAxiom<?>) data.create(ONT_DATA_FACTORY);
7473

7574
Assert.assertTrue(isONT(ont));
7675
Assert.assertTrue(isOWL(owl));

src/test/java/com/github/owlcs/ontapi/tests/jena/OntExpressionTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414

1515
package com.github.owlcs.ontapi.tests.jena;
1616

17+
import com.github.owlcs.ontapi.jena.OntJenaException;
18+
import com.github.owlcs.ontapi.jena.OntModelFactory;
19+
import com.github.owlcs.ontapi.jena.model.*;
20+
import com.github.owlcs.ontapi.jena.vocabulary.OWL;
21+
import com.github.owlcs.ontapi.jena.vocabulary.RDF;
22+
import com.github.owlcs.ontapi.jena.vocabulary.XSD;
23+
import com.github.owlcs.ontapi.utils.ReadWriteUtils;
1724
import org.apache.jena.rdf.model.Literal;
1825
import org.apache.jena.rdf.model.RDFList;
1926
import org.apache.jena.rdf.model.RDFNode;
@@ -22,13 +29,6 @@
2229
import org.junit.Test;
2330
import org.slf4j.Logger;
2431
import org.slf4j.LoggerFactory;
25-
import com.github.owlcs.ontapi.jena.OntJenaException;
26-
import com.github.owlcs.ontapi.jena.OntModelFactory;
27-
import com.github.owlcs.ontapi.jena.model.*;
28-
import com.github.owlcs.ontapi.jena.vocabulary.OWL;
29-
import com.github.owlcs.ontapi.jena.vocabulary.RDF;
30-
import com.github.owlcs.ontapi.jena.vocabulary.XSD;
31-
import com.github.owlcs.ontapi.utils.ReadWriteUtils;
3232

3333
import java.util.*;
3434
import java.util.stream.Collectors;
@@ -52,7 +52,7 @@ public void testCreateCardinalityRestrictions() {
5252
OntCE.DataMinCardinality r2 = m.createDataMinCardinality(dp, 1, null);
5353
OntCE.DataMaxCardinality r3 = m.createDataMaxCardinality(dp, 2, m.getRDFSLiteral());
5454
OntCE.ObjectMinCardinality r4 = m.createObjectMinCardinality(op, 12, m.getOWLThing());
55-
OntCE.CardinalityRestrictionCE r5 = m.createDataCardinality(dp, 0, m.getDatatype(XSD.xstring));
55+
OntCE.CardinalityRestrictionCE<?, ?> r5 = m.createDataCardinality(dp, 0, m.getDatatype(XSD.xstring));
5656
ReadWriteUtils.print(m);
5757

5858
Assert.assertTrue(r1.isQualified());

src/test/java/com/github/owlcs/ontapi/tests/jena/OntListTest.java

+15-13
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414

1515
package com.github.owlcs.ontapi.tests.jena;
1616

17-
import org.apache.jena.graph.Factory;
18-
import org.apache.jena.rdf.model.*;
19-
import org.apache.jena.util.iterator.NullIterator;
20-
import org.apache.jena.vocabulary.RDFS;
21-
import org.apache.jena.vocabulary.XSD;
22-
import org.junit.Assert;
23-
import org.junit.Test;
24-
import org.slf4j.Logger;
25-
import org.slf4j.LoggerFactory;
2617
import com.github.owlcs.ontapi.jena.OntJenaException;
2718
import com.github.owlcs.ontapi.jena.OntModelFactory;
2819
import com.github.owlcs.ontapi.jena.impl.OntGraphModelImpl;
@@ -34,8 +25,20 @@
3425
import com.github.owlcs.ontapi.jena.vocabulary.OWL;
3526
import com.github.owlcs.ontapi.jena.vocabulary.RDF;
3627
import com.github.owlcs.ontapi.utils.ReadWriteUtils;
28+
import org.apache.jena.graph.Factory;
29+
import org.apache.jena.rdf.model.*;
30+
import org.apache.jena.util.iterator.NullIterator;
31+
import org.apache.jena.vocabulary.RDFS;
32+
import org.apache.jena.vocabulary.XSD;
33+
import org.junit.Assert;
34+
import org.junit.Test;
35+
import org.slf4j.Logger;
36+
import org.slf4j.LoggerFactory;
3737

38-
import java.util.*;
38+
import java.util.Arrays;
39+
import java.util.Collections;
40+
import java.util.List;
41+
import java.util.Set;
3942
import java.util.stream.Collectors;
4043

4144
/**
@@ -334,7 +337,6 @@ public void testListSpec() {
334337
Assert.assertEquals(0, list.spec().count());
335338
}
336339

337-
@SuppressWarnings("unchecked")
338340
@Test
339341
public void testTypedList() {
340342
OntGraphModelImpl m = new OntGraphModelImpl(Factory.createDefaultGraph(), OntModelConfig.ONT_PERSONALITY_LAX);
@@ -347,9 +349,9 @@ public void testTypedList() {
347349

348350
OntObject s = m.createResource("list").as(OntObject.class);
349351
Property p = m.createProperty("of");
350-
OntList list = OntListImpl.create(m, s, p, RDF.List, RDFNode.class, Iter.of(a, b, c, d, e));
352+
OntList<RDFNode> list = OntListImpl.create(m, s, p, RDF.List, RDFNode.class, Iter.of(a, b, c, d, e));
351353
ReadWriteUtils.print(m);
352-
Assert.assertEquals(RDF.List, ((Optional<Resource>) list.type()).orElseThrow(AssertionError::new));
354+
Assert.assertEquals(RDF.List, list.type().orElseThrow(AssertionError::new));
353355
Assert.assertEquals(16, m.size());
354356
Assert.assertEquals(15, list.spec().count());
355357
Assert.assertEquals(16, list.content().count());

src/test/java/com/github/owlcs/ontapi/tests/jena/OntModelTest.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414

1515
package com.github.owlcs.ontapi.tests.jena;
1616

17-
import org.apache.jena.graph.Graph;
18-
import org.apache.jena.rdf.model.*;
19-
import org.apache.jena.riot.Lang;
20-
import org.hamcrest.core.IsEqual;
21-
import org.junit.Assert;
22-
import org.junit.Test;
23-
import org.slf4j.Logger;
24-
import org.slf4j.LoggerFactory;
2517
import com.github.owlcs.ontapi.OntFormat;
2618
import com.github.owlcs.ontapi.jena.OntJenaException;
2719
import com.github.owlcs.ontapi.jena.OntModelFactory;
@@ -38,6 +30,14 @@
3830
import com.github.owlcs.ontapi.jena.vocabulary.RDF;
3931
import com.github.owlcs.ontapi.jena.vocabulary.XSD;
4032
import com.github.owlcs.ontapi.utils.ReadWriteUtils;
33+
import org.apache.jena.graph.Graph;
34+
import org.apache.jena.rdf.model.*;
35+
import org.apache.jena.riot.Lang;
36+
import org.hamcrest.core.IsEqual;
37+
import org.junit.Assert;
38+
import org.junit.Test;
39+
import org.slf4j.Logger;
40+
import org.slf4j.LoggerFactory;
4141

4242
import java.io.IOException;
4343
import java.io.InputStream;
@@ -69,6 +69,7 @@ private static void testPizzaCEs(Model m, Property predicate, List<? extends Ont
6969
.toSet().size(), ces.size());
7070
}
7171

72+
@SuppressWarnings("rawtypes")
7273
static void simplePropertiesValidation(OntGraphModel ont) {
7374
Model jena = ModelFactory.createModelForGraph(ont.getGraph());
7475
Set<Resource> annotationProperties = jena.listStatements(null, RDF.type, OWL.AnnotationProperty)
@@ -103,6 +104,7 @@ static void simplePropertiesValidation(OntGraphModel ont) {
103104
ont.objectProperties().flatMap(OntOPE::inverseProperties).count());
104105
}
105106

107+
@SuppressWarnings("rawtypes")
106108
@Test
107109
public void testPizzaLoadCE() {
108110
LOGGER.debug("load pizza");
@@ -412,7 +414,7 @@ public void testObjectsContent() {
412414
OntIndividual i1 = class5.createIndividual("i1");
413415
OntIndividual i2 = class6.createIndividual();
414416
// nap:
415-
OntNPA npa1 = p1.addNegativeAssertion(i1, m.createLiteral("xxx"));
417+
OntNPA<?, ?> npa1 = p1.addNegativeAssertion(i1, m.createLiteral("xxx"));
416418

417419
ReadWriteUtils.print(m);
418420

@@ -495,7 +497,7 @@ public void testRemoveObjects() {
495497
OntCE class6 = m.createIntersectionOf(m.getOWLThing(), class2, class4, class5);
496498
Assert.assertEquals(6, m.ontObjects(OntCE.class).count());
497499
long size = m.size();
498-
OntDisjoint d = m.createDisjointClasses(m.getOWLNothing(), class1, class6);
500+
OntDisjoint<?> d = m.createDisjointClasses(m.getOWLNothing(), class1, class6);
499501
ReadWriteUtils.print(m);
500502

501503
m.removeOntObject(d);
@@ -655,7 +657,7 @@ public void testCycleModelImports() {
655657
public void testOntPropertyOrdinal() {
656658
Graph g = ReadWriteUtils.loadResourceTTLFile("/ontapi/pizza.ttl").getGraph();
657659
OntGraphModel m = OntModelFactory.createModel(g);
658-
OntProperty p = m.getOntEntity(OntProperty.class, m.expandPrefix(":isIngredientOf"));
660+
OntProperty<?> p = m.getOntEntity(OntProperty.class, m.expandPrefix(":isIngredientOf"));
659661
Assert.assertNotNull(p);
660662
Assert.assertEquals(0, p.getOrdinal());
661663
Assert.assertEquals(0, m.getRDFSComment().getOrdinal());

0 commit comments

Comments
 (0)