if (!Iterables.contains(pathComponents, RestconfConstants.MOUNT)) {
final String moduleName = validateAndGetModulName(componentIter);
final Revision revision = validateAndGetRevision(componentIter);
- final Module module = schemaContext.findModule(moduleName, revision).orElse(null);
+ final Module module = schemaContext.findModule(moduleName, revision).orElseThrow();
return new SchemaExportContext(schemaContext, module, sourceProvider);
} else {
final StringBuilder pathBuilder = new StringBuilder();
final String moduleName = validateAndGetModulName(componentIter);
final Revision revision = validateAndGetRevision(componentIter);
final EffectiveModelContext context = coerceModelContext(point.getMountPoint());
- final Module module = context.findModule(moduleName, revision).orElse(null);
+ final Module module = context.findModule(moduleName, revision).orElseThrow();
return new SchemaExportContext(context, module, sourceProvider);
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.when;
import java.io.FileNotFoundException;
+import java.util.NoSuchElementException;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
}
/**
- * Get schema with identifier of not-existing module. <code>SchemaExportContext</code> is still created, but module
- * should be set to <code>null</code>.
+ * Get schema with identifier of not-existing module. Trying to create <code>SchemaExportContext</code> with
+ * not-existing module should result in error.
*/
@Test
public void getSchemaForNotExistingModuleTest() {
// prepare conditions - return not-mount point schema context
when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT);
- // make test
- final SchemaExportContext exportContext = schemaService.getSchema(NOT_EXISTING_MODULE);
-
- // verify
- assertNotNull("Export context should not be null", exportContext);
- assertNull("Not-existing module should not be found", exportContext.getModule());
+ // make test & verify
+ assertThrows(NoSuchElementException.class, () -> schemaService.getSchema(NOT_EXISTING_MODULE));
}
/**
}
/**
- * Get schema with identifier of not-existing module behind mount point. <code>SchemaExportContext</code> is still
- * created, but module should be set to <code>null</code>.
+ * Get schema with identifier of not-existing module behind mount point. Trying to create
+ * <code>SchemaExportContext</code> with not-existing module behind mount point should result in error.
*/
@Test
public void getSchemaForNotExistingModuleMountPointTest() {
// prepare conditions - return schema context with mount points
when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT_WITH_MOUNT_POINTS);
- // make test
- final SchemaExportContext exportContext = schemaService.getSchema(MOUNT_POINT + NOT_EXISTING_MODULE);
-
- // verify
- assertNotNull("Export context should not be null", exportContext);
- assertNull("Not-existing module should not be found", exportContext.getModule());
+ // make test & verify
+ assertThrows(NoSuchElementException.class, () -> schemaService.getSchema(MOUNT_POINT + NOT_EXISTING_MODULE));
}
/**
import java.util.List;
import java.util.Map.Entry;
+import java.util.NoSuchElementException;
import java.util.Optional;
import org.junit.AfterClass;
import org.junit.Before;
/**
* Test of getting <code>SchemaExportContext</code> when desired module is not found.
- * <code>SchemaExportContext</code> should be created but module should be set to <code>null</code>.
+ * <code>SchemaExportContext</code> should not be created and exception is thrown.
*/
@Test
public void toSchemaExportContextFromIdentifierNotFoundTest() {
- final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
+ assertThrows(NoSuchElementException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
SCHEMA_CONTEXT,
"not-existing-module" + "/" + "2016-01-01",
- null, sourceProvider);
-
- assertNotNull("Export context should be parsed", exportContext);
- assertNull("Not-existing module should be null", exportContext.getModule());
+ null, sourceProvider));
}
/**
/**
* Negative test of getting <code>SchemaExportContext</code> when desired module is not found behind mount point.
- * <code>SchemaExportContext</code> should be still created but module should be set to <code>null</code>.
+ * <code>SchemaExportContext</code> should not be created and exception is thrown.
*/
@Test
public void toSchemaExportContextFromIdentifierMountPointNotFoundTest() {
- final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
+ assertThrows(NoSuchElementException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
SCHEMA_CONTEXT,
MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01",
- mountPointService, sourceProvider);
-
- assertNotNull("Export context should be parsed", exportContext);
- assertNull("Not-existing module should be null", exportContext.getModule());
+ mountPointService, sourceProvider));
}
/**