### Question:
ItemDefinitionUtils { Optional<String> getPrefixForNamespaceURI(final String namespace) { final Definitions definitions = dmnGraphUtils.getModelDefinitions(); return definitions == null ? Optional.empty() : definitions.getPrefixForNamespaceURI(namespace); } @Inject  ItemDefinitionUtils(final DMNGraphUtils dmnGraphUtils); Optional<ItemDefinition> findByName(final String name); List<ItemDefinition> all(); void addItemDefinitions(final List<ItemDefinition> newItemDefinitions); String getConstraintText(final ItemDefinition itemDefinition); QName normaliseTypeRef(final QName typeRef);  }### Answer:
@Test public void testGetPrefixForNamespaceURIWhenDefinitionsIsNull() { final String namespaceURI = FEEL.getUri(); when(dmnGraphUtils.getModelDefinitions()).thenReturn(null); final Optional<String> prefix = utils.getPrefixForNamespaceURI(namespaceURI); assertFalse(prefix.isPresent()); }
@Test public void testGetPrefixForNamespaceURIWhenPrefixForNamespaceURIIsNotPresent() { final String namespaceURI = FEEL.getUri(); final Definitions definitions = mock(Definitions.class); when(dmnGraphUtils.getModelDefinitions()).thenReturn(definitions); when(definitions.getPrefixForNamespaceURI(namespaceURI)).thenReturn(Optional.empty()); final Optional<String> prefix = utils.getPrefixForNamespaceURI(namespaceURI); assertFalse(prefix.isPresent()); }
@Test public void testGetPrefixForNamespaceURIWhenPrefixForNamespaceURIIsPresent() { final String namespaceURI = FEEL.getUri(); final Definitions definitions = mock(Definitions.class); final Optional<String> expectedPrefix = Optional.of("prefix"); when(dmnGraphUtils.getModelDefinitions()).thenReturn(definitions); when(definitions.getPrefixForNamespaceURI(namespaceURI)).thenReturn(expectedPrefix); final Optional<String> actualPrefix = utils.getPrefixForNamespaceURI(namespaceURI); assertEquals(expectedPrefix, actualPrefix); }