ModelBuilder { public ModelBuilder add(Resource subject, IRI predicate, Object object) { Value objectValue = null; if (object instanceof Value) { objectValue = (Value) object; } else if (object instanceof String) { objectValue = convertPrefixedName((String) object); } if (objectValue == null) { model.setNamespace(XSD.NS); objectValue = Literals.createLiteral(SimpleValueFactory.getInstance(), object); } if (currentNamedGraph != null) { model.add(subject, predicate, objectValue, currentNamedGraph); } else { model.add(subject, predicate, objectValue); } return this; } ModelBuilder();  ModelBuilder(Model model); ModelBuilder setNamespace(Namespace ns); ModelBuilder setNamespace(String prefix, String namespace); ModelBuilder subject(Resource subject); ModelBuilder subject(String prefixedNameOrIri); ModelBuilder namedGraph(Resource namedGraph); ModelBuilder namedGraph(String prefixedNameOrIRI); ModelBuilder defaultGraph(); ModelBuilder add(Resource subject, IRI predicate, Object object); ModelBuilder add(String subject, IRI predicate, Object object); ModelBuilder add(String subject, String predicate, Object object); ModelBuilder add(IRI predicate, Object object); ModelBuilder add(String predicate, Object object); Model build();  }
@Test public void testAddPredicateObject1() { try { testBuilder.add(RDF.TYPE, RDFS.CLASS); fail("add should have failed with model exception: subject not set"); } catch (ModelException e) { } }
@Test public void testAddWithStringSubject() { testBuilder.add("foaf:Person", RDF.TYPE, RDFS.CLASS); assertTrue(model.contains(FOAF.PERSON, RDF.TYPE, RDFS.CLASS)); }
@Test public void testAddWithUnknownStringSubject() { testBuilder.add("ex:Person", RDF.TYPE, RDFS.CLASS); assertTrue(model.contains(SimpleValueFactory.getInstance().createIRI("ex:Person"), RDF.TYPE, RDFS.CLASS)); }
@Test public void testAddWithIllegalStringSubject() { try { testBuilder.add("Johnny", RDF.TYPE, RDFS.CLASS); fail("should have failed on illegal IRI for subject"); } catch (ModelException e) { } }