### Question:
TermGeneratorCreator { @SuppressWarnings("unchecked") TermGenerator<Value> getObjectGenerator(ObjectMap map) { return (TermGenerator<Value>) getGenerator( map, ImmutableSet.of(TermType.IRI, TermType.BLANK_NODE, TermType.LITERAL), ImmutableSet.of(IRI.class, Literal.class) ); } TermGeneratorCreator(
		ValueFactory valueFactory,
		String baseIri,
		Function<String, String> makeIriSafe,
		TemplateParser templateParser,
		RmlMapper mapper
	);   }### Answer:
@Test public void getGenerator_withReferenceAndTemplate_throwsRuntimeException() throws Exception { TermGeneratorCreator tgc = new TermGeneratorCreator(null, "foo", null, TemplateParser.build(), null); RuntimeException exception = assertThrows(RuntimeException.class, () -> tgc.getObjectGenerator(new CarmlObjectMap("foo.bar", null, "foo{foo.bar}", TermType.LITERAL, null, null, null, null))); Assert.assertNotNull(exception); Assert.assertTrue(exception.getMessage().startsWith("2 value generators were created for term map")); }
@Test public void IriTermGenerator_withRelativeIRI_usesBaseIRI() throws Exception { ValueFactory f = SimpleValueFactory.getInstance(); String baseIri = "http: TermGeneratorCreator tgc = new TermGeneratorCreator(f, baseIri, null, TemplateParser.build(), null); String ref = "ref"; TermGenerator<Value> generator = tgc.getObjectGenerator(new CarmlObjectMap(ref, null, null, TermType.IRI, null, null, null, null)); String relativeIriPart = "/relativeIriPortion"; EvaluateExpression evaluator = Mockito.mock(EvaluateExpression.class); when(evaluator.apply(ref)).thenReturn(Optional.of(relativeIriPart)); List<Value> result = generator.apply(evaluator); Assert.assertTrue(!result.isEmpty()); Assert.assertTrue(result.get(0) instanceof IRI); Assert.assertEquals(result.get(0), f.createIRI(baseIri + relativeIriPart)); }
@Test public void IriTermGenerator_withAbsoluteIRI_usesBaseIRI() throws Exception { ValueFactory f = SimpleValueFactory.getInstance(); String baseIri = "http: TermGeneratorCreator tgc = new TermGeneratorCreator(f, baseIri, null, TemplateParser.build(), null); String ref = "ref"; TermGenerator<Value> generator = tgc.getObjectGenerator(new CarmlObjectMap(ref, null, null, TermType.IRI, null, null, null, null)); String absoluteIri = "http: EvaluateExpression evaluator = Mockito.mock(EvaluateExpression.class); when(evaluator.apply(ref)).thenReturn(Optional.of(absoluteIri)); List<Value> result = generator.apply(evaluator); Assert.assertTrue(!result.isEmpty()); Assert.assertTrue(result.get(0) instanceof IRI); Assert.assertEquals(result.get(0), f.createIRI(absoluteIri)); }
@Test public void IriTermGenerator_withFaultyIRI_throwsException() throws Exception { ValueFactory f = SimpleValueFactory.getInstance(); String baseIri = "?"; TermGeneratorCreator tgc = new TermGeneratorCreator(f, baseIri, null, TemplateParser.build(), null); String ref = "ref"; TermGenerator<Value> generator = tgc.getObjectGenerator(new CarmlObjectMap(ref, null, null, TermType.IRI, null, null, null, null)); String relativeIriPart = "/relativeIriPortion"; EvaluateExpression evaluator = Mockito.mock(EvaluateExpression.class); when(evaluator.apply(ref)).thenReturn(Optional.of(relativeIriPart)); RuntimeException exception = null; try { generator.apply(evaluator); Assert.assertTrue("This code should be unreachable", false); } catch (RuntimeException e) { exception = e; } Assert.assertNotNull(exception); Assert.assertTrue(exception.getMessage().startsWith("Could not generate a valid iri")); }