JNDIInvoker { public static void mapDatasource(Map map, List<ConfigProperty> props) throws NamingException, DataSourceCreateException, ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException { mapDatasource(map, props, dataSourceFactory, ctx); }  static void mapTransactions(DistributedSystem distSystem); static void mapDatasource(Map map, List<ConfigProperty> props); static void unMapDatasource(String jndiName); static DataSource getDataSource(String name); static boolean isValidDataSource(String name); static Context getJNDIContext(); static TransactionManager getTransactionManager(); static int getNoOfAvailableDataSources(); static Map<String, String> getBindingNamesRecursively(Context ctx);  }
@Test public void verifyThatMapDataSourceWithGetSimpleDataSourceThrowingWillThrowThatException() throws Exception { Map<String, String> inputs = new HashMap<>(); Context context = mock(Context.class); DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class); DataSourceCreateException exception = mock(DataSourceCreateException.class); doThrow(exception).when(dataSourceFactory).getSimpleDataSource(any()); inputs.put("type", "SimpleDataSource"); Throwable thrown = catchThrowable(() -> JNDIInvoker.mapDatasource(inputs, null, dataSourceFactory, context)); assertThat(thrown).isSameAs(exception); }