Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
Cleaner unit test for ModelTripleHandler.java
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Jul 10, 2013
1 parent 4fd8400 commit 7168cc8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Expand Up @@ -31,7 +31,7 @@ public class ModelTripleHandler implements TripleHandler, AutoCloseable {
/**
* A {@link Model} of {@link Triple}s we are collecting.
*/
protected Model model = createDefaultModel();
protected final Model model = createDefaultModel();

private static final Logger LOGGER = getLogger(ModelTripleHandler.class);

Expand Down Expand Up @@ -86,7 +86,7 @@ public Model getModel() {
*/
@Override
public void close() throws TripleHandlerException {
model = null;
model.removeAll();
}

/*
Expand Down Expand Up @@ -149,4 +149,8 @@ public void receiveNamespace(final String prefix, final String uri,
public void closeContext(final ExtractionContext ec)
throws TripleHandlerException {
}

public void reset() {
model.removeAll();
}
}
@@ -1,14 +1,12 @@
package org.fcrepo.triplegenerators.tei;


import static com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.File;
import java.io.IOException;
import java.util.Set;

import org.apache.any23.Any23;
import org.apache.any23.extractor.ExtractionException;
Expand All @@ -20,6 +18,8 @@
import org.junit.Test;
import org.slf4j.Logger;

import com.hp.hpl.jena.rdf.model.Model;

/**
* Tests for {@link SetTripleHandler}
*
Expand All @@ -28,7 +28,7 @@
*/
public class TestModelTripleHandler extends ModelTripleHandler {

private static final Logger logger = getLogger(TestModelTripleHandler.class);
private static final Logger LOGGER = getLogger(TestModelTripleHandler.class);

private final Any23 any23 = new Any23();

Expand All @@ -44,11 +44,11 @@ public void setUp() {
}

/**
* "Zeros-out" the {@link Set} of {@link Triple}s being accumulated.
* "Zeros-out" the {@link Model} being accumulated.
*/
@After
public void resetModel() {
this.model = createDefaultModel();
reset();
}

/**
Expand All @@ -62,7 +62,7 @@ public void resetModel() {
@Test
public void testOneTriple() throws IOException, ExtractionException,
TripleHandlerException {
logger.info("Running testOneTriple()...");
LOGGER.info("Running testOneTriple()...");
any23.extract(rdfXmlSource, this);
assertTrue(
"Didn't find appropriate triple!",
Expand All @@ -71,7 +71,7 @@ public void testOneTriple() throws IOException, ExtractionException,
model.createResource("info:fedora/uva-lib:1038847"),
model.createProperty("http://fedora.lib.virginia.edu/relationships#testPredicate"),
model.createResource("info:test/resource")));
logger.info("Found appropriate triple.");
LOGGER.info("Found appropriate triple.");
close();
}

Expand All @@ -87,7 +87,7 @@ public void testOneTriple() throws IOException, ExtractionException,
@Test
public void testOneTripleWithLiteral() throws IOException,
ExtractionException, TripleHandlerException {
logger.info("Running testOneTripleWithLiteral()...");
LOGGER.info("Running testOneTripleWithLiteral()...");
any23.extract(rdfXmlSource, this);
assertTrue(
"Didn't find appropriate triple!",
Expand All @@ -96,7 +96,7 @@ public void testOneTripleWithLiteral() throws IOException,
model.createResource("info:fedora/uva-lib:1038847"),
model.createProperty("http://fedora.lib.virginia.edu/relationships#testPredicateWithLiteral"),
model.createLiteral("literal value")));
logger.info("Found appropriate triple.");
LOGGER.info("Found appropriate triple.");
close();
}

Expand All @@ -114,7 +114,7 @@ public void testOneTripleWithLiteral() throws IOException,
@Test
public void testOneTripleWithRelativeUri() throws IOException,
ExtractionException, TripleHandlerException {
logger.info("Running testOneTripleWithRelativeUri()...");
LOGGER.info("Running testOneTripleWithRelativeUri()...");
any23.extract(rdfXmlSource, this);
assertTrue(
"Didn't find appropriate triple!",
Expand All @@ -123,7 +123,7 @@ public void testOneTripleWithRelativeUri() throws IOException,
model.createResource("info:fedora/uva-lib:1038847"),
model.createProperty("http://fedora.lib.virginia.edu/relationships#testPredicateWithLiteral"),
model.createLiteral("/relative/uri/")));
logger.info("Found appropriate triple.");
LOGGER.info("Found appropriate triple.");
close();
}

Expand All @@ -133,12 +133,12 @@ public void testOneTripleWithRelativeUri() throws IOException,
*/
@Test
public void testSetContentLength() {
logger.info("Running testSetContentLength()...");
LOGGER.info("Running testSetContentLength()...");
try {
setContentLength(0);
fail("setContentLength() didn't throw an UnsupportedOperationException!");
} catch (final UnsupportedOperationException e) {
logger.info("Found correct behavior for setContentLength().");
LOGGER.info("Found correct behavior for setContentLength().");
}
}

Expand Down

0 comments on commit 7168cc8

Please sign in to comment.