From fff458c8546d3db141c2eb2d9a1b2e2beba00709 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Thu, 9 Jan 2025 14:17:55 -0800 Subject: [PATCH] Add support for double property values Fixes #7 --- .../ExternalJavaClassTemplate.txt | 27 ++++ .../javaTemplates/IndividualClassTemplate.txt | 27 ++++ resources/javaTemplates/JavaClassTemplate.txt | 142 ++++++++++++++++++ resources/javaTemplates/PomTemplate.txt | 4 +- .../TestValuesGeneratorTemplate.txt | 18 +++ resources/javaTemplates/UnitTestTemplate.txt | 24 +++ .../spdx/tools/model2java/ShaclToJava.java | 32 ++-- .../model2java/ShaclToJavaConstants.java | 7 +- .../tools/model2java/ShaclToJavaTest.java | 9 +- 9 files changed, 270 insertions(+), 20 deletions(-) diff --git a/resources/javaTemplates/ExternalJavaClassTemplate.txt b/resources/javaTemplates/ExternalJavaClassTemplate.txt index 0b5f918..ae5ad04 100644 --- a/resources/javaTemplates/ExternalJavaClassTemplate.txt +++ b/resources/javaTemplates/ExternalJavaClassTemplate.txt @@ -337,6 +337,33 @@ public class External{{{className}}} extends {{{className}}} implements Individ throw new InvalidSPDXAnalysisException("External elements can not set properties"); } {{/integerProperties}} + {{#doubleProperties}} + {{#nonOptional}} + /** + * @return the {{{propertyName}}} + */ + public @Nullable Double {{{getter}}}() throws InvalidSPDXAnalysisException { + return null; + } + {{/nonOptional}} + {{^nonOptional}} + /** + * @return the {{{propertyName}}} + */ + public Optional<{{{type}}}> {{{getter}}}() throws InvalidSPDXAnalysisException { + return Optional.empty(); + } + {{/nonOptional}} + + /** + * @param {{{propertyName}}} the {{{propertyName}}} to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public {{{className}}} {{{setter}}}(@Nullable {{{type}}} {{{propertyName}}}) throws InvalidSPDXAnalysisException { + throw new InvalidSPDXAnalysisException("External elements can not set properties"); + } + {{/doubleProperties}} {{#stringProperties}} {{#nonOptional}} /** diff --git a/resources/javaTemplates/IndividualClassTemplate.txt b/resources/javaTemplates/IndividualClassTemplate.txt index 2f7d061..030b2eb 100644 --- a/resources/javaTemplates/IndividualClassTemplate.txt +++ b/resources/javaTemplates/IndividualClassTemplate.txt @@ -286,6 +286,33 @@ public class {{{className}}} extends {{{superClass}}} implements IndividualUriVa throw new InvalidSPDXAnalysisException("Can not set or modify a property of an Individual type"); } {{/integerProperties}} + {{#doubleProperties}} + {{#nonOptional}} + /** + * @return the {{{propertyName}}} + */ + public @Nullable Double {{{getter}}}() throws InvalidSPDXAnalysisException { + return null; + } + {{/nonOptional}} + {{^nonOptional}} + /** + * @return the {{{propertyName}}} + */ + public Optional<{{{type}}}> {{{getter}}}() throws InvalidSPDXAnalysisException { + return Optional.empty(); + } + {{/nonOptional}} + + /** + * @param {{{propertyName}}} the {{{propertyName}}} to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public {{{className}}} {{{setter}}}(@Nullable {{{type}}} {{{propertyName}}}) throws InvalidSPDXAnalysisException { + throw new InvalidSPDXAnalysisException("Can not set or modify a property of an Individual type"); + } + {{/doubleProperties}} {{#stringProperties}} {{#nonOptional}} /** diff --git a/resources/javaTemplates/JavaClassTemplate.txt b/resources/javaTemplates/JavaClassTemplate.txt index 4e80d76..7be6588 100644 --- a/resources/javaTemplates/JavaClassTemplate.txt +++ b/resources/javaTemplates/JavaClassTemplate.txt @@ -261,6 +261,18 @@ public {{#abstract}}abstract{{/abstract}} class {{{className}}} extends {{{super {{/nonOptional}} {{/superSetter}} {{/integerProperties}} + {{#doubleProperties}} + {{^superSetter}} + {{#nonOptional}} + if (Objects.nonNull(builder.{{{propertyName}}})) { + {{{setter}}}(builder.{{{propertyName}}}); + } + {{/nonOptional}} + {{^nonOptional}} + {{{setter}}}(builder.{{{propertyName}}}); + {{/nonOptional}} + {{/superSetter}} + {{/doubleProperties}} {{#stringProperties}} {{^superSetter}} {{#nonOptional}} @@ -753,6 +765,67 @@ public {{#abstract}}abstract{{/abstract}} class {{{className}}} extends {{{super } {{/superSetter}} {{/integerProperties}} + {{#doubleProperties}} + {{^superSetter}} + {{#nonOptional}} + /** + * @return the {{{propertyName}}} + */ + public @Nullable Double {{{getter}}}() throws InvalidSPDXAnalysisException { + Optional retval = getDoublePropertyValue(SpdxConstantsV3.{{{propertyConstant}}}); + return retval.isPresent() ? retval.get() : null; + } + {{/nonOptional}} + {{^nonOptional}} + /** + * @return the {{{propertyName}}} + */ + public Optional<{{{type}}}> {{{getter}}}() throws InvalidSPDXAnalysisException { + return getDoublePropertyValue(SpdxConstantsV3.{{{propertyConstant}}}); + } + {{/nonOptional}} + + /** + * @param {{{propertyName}}} the {{{propertyName}}} to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public {{{className}}} {{{setter}}}(@Nullable {{{type}}} {{{propertyName}}}) throws InvalidSPDXAnalysisException { + {{#required}} + if (isStrict() && Objects.isNull({{{propertyName}}})) { + throw new InvalidSPDXAnalysisException("{{{propertyName}}} is a required property"); + } + {{/required}} + {{#min}} + if (isStrict() && Objects.nonNull({{{propertyName}}}) && {{{propertyName}}} < {{{min}}}) { + throw new InvalidSPDXAnalysisException("{{{propertyName}}} value " + {{{propertyName}}} + " is less than the minimum {{{min}}} in {{{className}}}"); + } + {{/min}} + {{#max}} + if (isStrict() && Objects.nonNull({{{propertyName}}}) && {{{propertyName}}} > {{{max}}}) { + throw new InvalidSPDXAnalysisException("{{{propertyName}}} value " + {{{propertyName}}} + " is greater than the maximum {{{max}}} in {{{className}}}"); + } + {{/max}} + {{#superSetter}} + super.{{{setter}}}({{{propertyName}}}); + {{/superSetter}} + setPropertyValue(SpdxConstantsV3.{{{propertyConstant}}}, {{{propertyName}}}); + return this; + } + {{/superSetter}} + {{#superSetter}} + /** + * @param {{{propertyName}}} the {{{propertyName}}} to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + @Override + public {{{className}}} {{{setter}}}(@Nullable {{{type}}} {{{propertyName}}}) throws InvalidSPDXAnalysisException { + super.{{{setter}}}({{{propertyName}}}); + return this; + } + {{/superSetter}} + {{/doubleProperties}} {{#stringProperties}} {{^superSetter}} {{#nonOptional}} @@ -1111,6 +1184,58 @@ public {{#abstract}}abstract{{/abstract}} class {{{className}}} extends {{{super } {{/superSetter}} {{/integerProperties}} + {{#doubleProperties}} + {{^superSetter}} + try { + {{#nonOptional}} + {{^hasConstraint}} + @SuppressWarnings("unused") + {{/hasConstraint}} + {{{type}}} {{{propertyName}}} = {{{getter}}}(); + {{#required}} + if (Objects.isNull({{{propertyName}}}) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { {{{requiredProfiles}}} }))) { + retval.add("Missing {{{propertyName}}} in {{{className}}}"); + } + {{/required}} + {{#min}} + if (Objects.nonNull({{{propertyName}}}) && {{{propertyName}}} < {{{min}}}) { + retval.add("{{{propertyName}}} value " + {{{propertyName}}} + " is less than the minimum {{{min}}} in {{{className}}}"); + } + {{/min}} + {{#max}} + if (Objects.nonNull({{{propertyName}}}) && {{{propertyName}}} > {{{max}}}) { + retval.add("{{{propertyName}}} value " + {{{propertyName}}} + " is greater than the maximum {{{max}}} in {{{className}}}"); + } + {{/max}} + {{/nonOptional}} + {{^nonOptional}} + {{^hasConstraint}} + @SuppressWarnings("unused") + {{/hasConstraint}} + Optional<{{{type}}}> {{{propertyName}}} = {{{getter}}}(); + {{#required}} + if (!{{{propertyName}}}.isPresent() && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { {{{requiredProfiles}}} }))) { + retval.add("Missing {{{propertyName}}} in {{{className}}}"); + } + {{/required}} + {{#min}} + if ({{{propertyName}}}.isPresent() && {{{propertyName}}}.get() < {{{min}}}) { + retval.add("{{{propertyName}}} value " + {{{propertyName}}}.get() + " is less than the minimum {{{min}}} in {{{className}}}"); + } + {{/min}} + {{#max}} + if ({{{propertyName}}}.isPresent() && {{{propertyName}}}.get() > {{{max}}}) { + retval.add("{{{propertyName}}} value " + {{{propertyName}}}.get() + " is greater than the maximum {{{max}}} in {{{className}}}"); + } + {{/max}} + {{/nonOptional}} + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting {{{propertyName}}} for {{{className}}}: "+e.getMessage()); + } + {{/superSetter}} + {{/doubleProperties}} {{#stringProperties}} {{^superSetter}} try { @@ -1330,6 +1455,11 @@ public {{#abstract}}abstract{{/abstract}} class {{{className}}} extends {{{super protected Integer {{{propertyName}}} = null; {{/superSetter}} {{/integerProperties}} + {{#doubleProperties}} + {{^superSetter}} + protected Double {{{propertyName}}} = null; + {{/superSetter}} + {{/doubleProperties}} {{#stringProperties}} {{^superSetter}} protected String {{{propertyName}}} = null; @@ -1536,6 +1666,18 @@ public {{#abstract}}abstract{{/abstract}} class {{{className}}} extends {{{super return this; } {{/integerProperties}} + {{#doubleProperties}} + + /** + * Sets the initial value of {{{propertyName}}} + * @parameter {{{propertyName}}} value to set + * @return this for chaining + **/ + public {{{className}}}Builder {{{setter}}}({{{type}}} {{{propertyName}}}) { + {{#superSetter}}super.{{/superSetter}}{{^superSetter}}this.{{/superSetter}}{{{propertyName}}} = {{{propertyName}}}; + return this; + } + {{/doubleProperties}} {{#stringProperties}} /** diff --git a/resources/javaTemplates/PomTemplate.txt b/resources/javaTemplates/PomTemplate.txt index ea913e0..1980f7c 100644 --- a/resources/javaTemplates/PomTemplate.txt +++ b/resources/javaTemplates/PomTemplate.txt @@ -2,7 +2,7 @@ 4.0.0 org.spdx spdx-java-model-3_0 - 1.0.0-RC1 + 1.0.0-RC2 spdx-java-model-3 Generated java model source code https://github.com/spdx/spdx-java-model-3_0 @@ -116,7 +116,7 @@ org.spdx spdx-java-core - 0.1.0-Alpha + 1.0.0-RC2 org.slf4j diff --git a/resources/javaTemplates/TestValuesGeneratorTemplate.txt b/resources/javaTemplates/TestValuesGeneratorTemplate.txt index 4af8c1b..29dcaeb 100644 --- a/resources/javaTemplates/TestValuesGeneratorTemplate.txt +++ b/resources/javaTemplates/TestValuesGeneratorTemplate.txt @@ -279,6 +279,18 @@ public class TestValuesGenerator { return this; } {{/integerProperties}} + {{#doubleProperties}} + + /** + * Sets the initial value of {{{propertyName}}} + * @parameter {{{propertyName}}} value to set + * @return this for chaining + **/ + public Mock{{{className}}}Builder {{{setter}}}({{{type}}} {{{propertyName}}}) { + {{#superSetter}}super.{{/superSetter}}{{^superSetter}}this.{{/superSetter}}{{{propertyName}}} = {{{propertyName}}}; + return this; + } + {{/doubleProperties}} {{#stringProperties}} /** @@ -299,6 +311,9 @@ public class TestValuesGenerator { {{#integerProperties}} public static final Integer {{{propertyNameUpper}}}_TEST_VALUE = 55; {{/integerProperties}} + {{#doubleProperties}} + public static final Double {{{propertyNameUpper}}}_TEST_VALUE = 55.1; + {{/doubleProperties}} {{#stringProperties}} {{^pattern}} public static final String {{{propertyNameUpper}}}_TEST_VALUE = "test {{{propertyName}}}"; @@ -366,6 +381,9 @@ public class TestValuesGenerator { {{#integerProperties}} .{{{setter}}}({{{propertyNameUpper}}}_TEST_VALUE) {{/integerProperties}} + {{#doubleProperties}} + .{{{setter}}}({{{propertyNameUpper}}}_TEST_VALUE) + {{/doubleProperties}} {{#stringProperties}} .{{{setter}}}({{{propertyNameUpper}}}_TEST_VALUE) {{/stringProperties}} diff --git a/resources/javaTemplates/UnitTestTemplate.txt b/resources/javaTemplates/UnitTestTemplate.txt index 86058de..570ca8b 100644 --- a/resources/javaTemplates/UnitTestTemplate.txt +++ b/resources/javaTemplates/UnitTestTemplate.txt @@ -255,6 +255,28 @@ public class {{{className}}}Test extends TestCase { {{/nonOptional}} } {{/integerProperties}} + {{#doubleProperties}} + + /** + * Test method for {@link {{{pkgName}}}.{{{className}}}#{{{setter}}}}. + */ + public void test{{{className}}}{{{setter}}}() throws InvalidSPDXAnalysisException { + {{{className}}} test{{{className}}} = generator.builderFor{{{className}}}Tests(TEST_OBJECT_URI).build(); + {{#nonOptional}} + assertEquals(TestValuesGenerator.{{{propertyNameUpper}}}_TEST_VALUE, test{{{className}}}.{{{getter}}}()); + {{/nonOptional}} + {{^nonOptional}} + assertEquals(Optional.of(TestValuesGenerator.{{{propertyNameUpper}}}_TEST_VALUE), test{{{className}}}.{{{getter}}}()); + {{/nonOptional}} + test{{{className}}}.{{{setter}}}(new Double(653.6)); + {{#nonOptional}} + assertEquals(new Double(653.6), test{{{className}}}.{{{getter}}}()); + {{/nonOptional}} + {{^nonOptional}} + assertEquals(Optional.of(new Double(653.6)), test{{{className}}}.{{{getter}}}()); + {{/nonOptional}} + } + {{/doubleProperties}} {{#stringProperties}} /** @@ -353,6 +375,8 @@ public class {{{className}}}Test extends TestCase { {{/booleanProperties}} {{#integerProperties}} {{/integerProperties}} + {{#doubleProperties}} + {{/doubleProperties}} {{#stringProperties}} {{/stringProperties}} {{#objectPropertyValueCollection}} diff --git a/src/main/java/org/spdx/tools/model2java/ShaclToJava.java b/src/main/java/org/spdx/tools/model2java/ShaclToJava.java index 92e7c4f..bbba2af 100644 --- a/src/main/java/org/spdx/tools/model2java/ShaclToJava.java +++ b/src/main/java/org/spdx/tools/model2java/ShaclToJava.java @@ -56,6 +56,7 @@ import com.github.mustachejava.DefaultMustacheFactory; import com.github.mustachejava.Mustache; +import static org.spdx.tools.model2java.ShaclToJavaConstants.RESERVED_JAVA_WORDS; import static org.spdx.tools.model2java.ShaclToJavaConstants.TYPE_PRED; /** @@ -96,6 +97,7 @@ public enum PropertyType { ENUM, BOOLEAN, INTEGER, + DOUBLE, STRING, OBJECT_COLLECTION, STRING_COLLECTION, @@ -164,7 +166,8 @@ private void createUriNameMapping(String uri, Map uriNameMap, String name = uriToName(uri); if (uri.equals(nameUriMap.get(name))) { return; // already there - } else if (nameUriMap.containsKey(name)) { + } + if (nameUriMap.containsKey(name)) { String profile = uriToProfile(uri); if ("Core".equalsIgnoreCase(profile)) { // replace the existing short name @@ -242,10 +245,6 @@ public List generate(File dir) throws IOException, ShaclToJavaException propertyShapes.put(ps.getPath().toString(), ps); } } - List subClasses = new ArrayList<>(); - ontClass.listSubClasses().forEach(oc -> { - subClasses.add(oc); - }); List superClasses = new ArrayList<>(); if (elementTypes.contains(classUri) || licenseAdditionTypes.contains(classUri) || @@ -343,7 +342,7 @@ private String classUriToExternalClassUri(String classUri) { */ private void generateTestValueGenerator(File dir, Map>> allPropertiesInUse, - Map> unitTestMaps) throws IOException { + Map> unitTestMaps) throws IOException, ShaclToJavaException { Map mustacheMap = new HashMap<>(); mustacheMap.put("versionSuffix", versionSuffix); mustacheMap.put("versionSemVer", versionSemVer); @@ -364,7 +363,7 @@ private void generateTestValueGenerator(File dir, requiredImports.add("import "+uriToPkg(typeUri) + "." + uriToClassName.get(typeUri) +";"); } } - String propTypeStr = ""; + String propTypeStr; switch (entry.getKey()) { case ELEMENT: propTypeStr = "elementProperties"; break; case OBJECT: propTypeStr = "objectProperties"; break; @@ -374,6 +373,7 @@ private void generateTestValueGenerator(File dir, case ENUM: propTypeStr = "enumerationProperties"; break; case BOOLEAN: propTypeStr = "booleanProperties"; break; case INTEGER: propTypeStr = "integerProperties"; break; + case DOUBLE: propTypeStr = "doubleProperties"; break; case STRING: propTypeStr = "stringProperties"; break; case OBJECT_COLLECTION: propTypeStr = "objectPropertyValueCollection"; break; case STRING_COLLECTION: propTypeStr = "stringCollection"; break; @@ -410,21 +410,23 @@ private void generateTestValueGenerator(File dir, requiredImports.add("import java.util.Collection;"); requiredImports.add("import java.util.Map;"); requiredImports.add("import java.util.HashMap;"); - List importList = new ArrayList(requiredImports); + List importList = new ArrayList<>(requiredImports); Collections.sort(importList); mustacheMap.put("imports", importList); Path path = dir.toPath().resolve("src").resolve("test").resolve("java").resolve("org") .resolve("spdx").resolve("library").resolve("model").resolve(versionSuffix); Files.createDirectories(path); File testValuesGeneratorFile = path.resolve("TestValuesGenerator.java").toFile(); - testValuesGeneratorFile.createNewFile(); + if (!testValuesGeneratorFile.createNewFile()) { + throw new ShaclToJavaException("Could not create test values generator file"); + } writeMustacheFile(ShaclToJavaConstants.TEST_VALUES_GENERATOR_TEMPLATE, testValuesGeneratorFile, mustacheMap); } /** * Generates the test mock files - * @param dir - * @throws IOException + * @param dir Directory for the mock files + * @throws IOException on I/O Error */ private void generateMockFiles(File dir) throws IOException { Path path = dir.toPath().resolve("src").resolve("test").resolve("java").resolve("org") @@ -921,7 +923,9 @@ private PropertyType determinePropertyType(@Nullable Node classTypeRestriction, return PropertyType.BOOLEAN; } else if (ShaclToJavaConstants.INTEGER_TYPES.contains(typeUri)) { return PropertyType.INTEGER; - } else if (ShaclToJavaConstants.STRING_TYPE.equals(typeUri) || ShaclToJavaConstants.DATE_TIME_TYPE.equals(typeUri) || + } else if (ShaclToJavaConstants.DOUBLE_TYPES.contains(typeUri)) { + return PropertyType.DOUBLE; + }else if (ShaclToJavaConstants.STRING_TYPE.equals(typeUri) || ShaclToJavaConstants.DATE_TIME_TYPE.equals(typeUri) || ShaclToJavaConstants.ANY_URI_TYPE.equals(typeUri) || stringTypes.contains(typeUri)) { if (Objects.isNull(maxRestriction) || maxRestriction > 1) { return PropertyType.STRING_COLLECTION; @@ -1113,6 +1117,7 @@ private String fillMustachMapsForClass(String classUri, String name, javaClassMap.put("enumerationProperties", propertyMap.get(PropertyType.ENUM)); javaClassMap.put("booleanProperties", propertyMap.get(PropertyType.BOOLEAN)); javaClassMap.put("integerProperties", propertyMap.get(PropertyType.INTEGER)); + javaClassMap.put("doubleProperties", propertyMap.get(PropertyType.DOUBLE)); javaClassMap.put("stringProperties", propertyMap.get(PropertyType.STRING)); javaClassMap.put("objectPropertyValueCollection", propertyMap.get(PropertyType.OBJECT_COLLECTION)); javaClassMap.put("stringCollection", propertyMap.get(PropertyType.STRING_COLLECTION)); @@ -1376,6 +1381,7 @@ private void generateIndividualClass(File dir, String individualUri, String name mustacheMap.put("enumerationProperties", propertyMap.get(PropertyType.ENUM)); mustacheMap.put("booleanProperties", propertyMap.get(PropertyType.BOOLEAN)); mustacheMap.put("integerProperties", propertyMap.get(PropertyType.INTEGER)); + mustacheMap.put("doubleProperties", propertyMap.get(PropertyType.DOUBLE)); mustacheMap.put("stringProperties", propertyMap.get(PropertyType.STRING)); mustacheMap.put("objectPropertyValueCollection", propertyMap.get(PropertyType.OBJECT_COLLECTION)); mustacheMap.put("stringCollection", propertyMap.get(PropertyType.STRING_COLLECTION)); @@ -1546,6 +1552,8 @@ private Map propertyToMustachMap(PropertyShape propertyShape, type = "String"; } else if (ShaclToJavaConstants.INTEGER_TYPES.contains(typeUri)) { type = "Integer"; + } else if (ShaclToJavaConstants.DOUBLE_TYPES.contains(typeUri)) { + type = "Double"; } else { type = uriToClassName.get(typeUri); if (!typeUri.startsWith(nameSpace) && diff --git a/src/main/java/org/spdx/tools/model2java/ShaclToJavaConstants.java b/src/main/java/org/spdx/tools/model2java/ShaclToJavaConstants.java index b288652..b570d37 100644 --- a/src/main/java/org/spdx/tools/model2java/ShaclToJavaConstants.java +++ b/src/main/java/org/spdx/tools/model2java/ShaclToJavaConstants.java @@ -85,8 +85,13 @@ public class ShaclToJavaConstants { INTEGER_TYPES.add("http://www.w3.org/2001/XMLSchema#unsignedInt"); INTEGER_TYPES.add("http://www.w3.org/2001/XMLSchema#unsignedShort"); INTEGER_TYPES.add("http://www.w3.org/2001/XMLSchema#unsignedByte"); - INTEGER_TYPES.add("http://www.w3.org/2001/XMLSchema#decimal"); } + + public static Set DOUBLE_TYPES = new HashSet<>(); + static { + DOUBLE_TYPES.add("http://www.w3.org/2001/XMLSchema#decimal"); + } + public static Map RESERVED_JAVA_WORDS = new HashMap<>(); static { diff --git a/src/test/java/org/spdx/tools/model2java/ShaclToJavaTest.java b/src/test/java/org/spdx/tools/model2java/ShaclToJavaTest.java index 49b1510..399733d 100644 --- a/src/test/java/org/spdx/tools/model2java/ShaclToJavaTest.java +++ b/src/test/java/org/spdx/tools/model2java/ShaclToJavaTest.java @@ -16,7 +16,6 @@ import org.apache.jena.ontology.OntModel; import org.apache.jena.ontology.OntModelSpec; import org.apache.jena.rdf.model.ModelFactory; -import org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException; import junit.framework.TestCase; @@ -36,11 +35,11 @@ protected void tearDown() throws Exception { super.tearDown(); } - public void testConvertToJava() throws IOException, XmlSchemaSerializerException, ShaclToJavaException { - ShaclToJava otj = null; + public void testConvertToJava() throws IOException, ShaclToJavaException { + ShaclToJava otj; File tempDir = Files.createTempDirectory("spdx_test").toFile(); try { - try (InputStream is = new FileInputStream(new File(MODEL_FILE_PATH))) { + try (InputStream is = new FileInputStream(MODEL_FILE_PATH)) { OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); model.read(is, "", "Turtle"); otj = new ShaclToJava(model); @@ -68,7 +67,7 @@ public void testConvertToJava() throws IOException, XmlSchemaSerializerException } /** - * @param tempDir + * @param tempDir directory to delete */ private boolean deleteDirectory(File tempDir) { File[] files = tempDir.listFiles();