Skip to content

Commit 9bc5627

Browse files
committed
Added unittest
Signed-off-by:Bart Hanssens <bart.hanssens@fedict.be>
1 parent f411906 commit 9bc5627

2 files changed

Lines changed: 52 additions & 17 deletions

File tree

core/model/src/main/java/org/eclipse/rdf4j/model/util/VocabUtil.java renamed to core/model/src/main/java/org/eclipse/rdf4j/model/util/VocabularyUtil.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,25 @@
1919
*
2020
* @author Bart Hanssens
2121
*/
22-
public class VocabUtil {
23-
22+
public class VocabularyUtil {
2423
/**
2524
* Get all the {@link IRI IRIs} of the classes and properties of a vocabulary.
26-
*
25+
*
2726
* @param vocabulary RDF vocabulary
2827
* @return set of IRIs
2928
*/
30-
public static Set<IRI> getVocabularyIRIs(Class vocabulary) {
31-
Set<IRI> iris = new HashSet<>();
32-
33-
for(Field f : vocabulary.getFields ()) {
34-
if (f.getType().equals(IRI.class) && Modifier.isPublic(f.getModifiers())) {
35-
try {
36-
iris.add((IRI) f.get(f));
37-
} catch (IllegalArgumentException|IllegalAccessException ex) {
38-
// should not happen
39-
}
40-
}
41-
}
42-
return iris;
29+
public static Set<IRI> getAllIRIs(Class vocabulary) {
30+
Set<IRI> iris = new HashSet<>();
31+
32+
for (Field f : vocabulary.getFields()) {
33+
if (f.getType().equals(IRI.class) && Modifier.isPublic(f.getModifiers())) {
34+
try {
35+
iris.add((IRI) f.get(f));
36+
} catch (IllegalArgumentException | IllegalAccessException ex) {
37+
// should not happen
38+
}
39+
}
40+
}
41+
return iris;
4342
}
44-
}
43+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (c) 2017 Eclipse RDF4J contributors, and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Distribution License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/org/documents/edl-v10.php.
7+
*/
8+
package org.eclipse.rdf4j.model.util;
9+
10+
import java.util.Arrays;
11+
import java.util.HashSet;
12+
import java.util.Set;
13+
14+
import org.eclipse.rdf4j.model.IRI;
15+
import org.eclipse.rdf4j.model.vocabulary.DC;
16+
17+
import org.junit.Test;
18+
import static org.junit.Assert.assertEquals;
19+
20+
/**
21+
* @author Bart Hanssens
22+
*/
23+
public class VocabularyUtilTest {
24+
25+
@Test
26+
public void testVocabAllIRI() throws Exception {
27+
Set<IRI> dcIRIs = new HashSet<>(Arrays.asList(
28+
DC.CONTRIBUTOR, DC.COVERAGE, DC.CREATOR, DC.DATE, DC.DESCRIPTION,
29+
DC.FORMAT, DC.IDENTIFIER, DC.LANGUAGE, DC.PUBLISHER, DC.RELATION,
30+
DC.RIGHTS, DC.SOURCE, DC.SUBJECT, DC.TITLE, DC.TYPE));
31+
32+
Set<IRI> allIRIs = VocabularyUtil.getAllIRIs(DC.class);
33+
34+
assertEquals(dcIRIs, allIRIs);
35+
}
36+
}

0 commit comments

Comments
 (0)