DbEnvironmentFactory { public DBEnvironment createEnvironmentInstance(String requestedEnv) { EnvironmentDescriptor descriptor = getEnvironmentDescriptor(requestedEnv); if (null == descriptor) { throw new IllegalArgumentException("DB Environment not supported:" + requestedEnv); } return descriptor.createEnvironmentInstance(); } private  DbEnvironmentFactory(); static DBEnvironment getDefaultEnvironment(); static void setDefaultEnvironment(DBEnvironment newDefaultEnvironment); static DbEnvironmentFactory newFactoryInstance(); void registerEnv(String environmentName, String driverClassName); EnvironmentDescriptor unregisterEnv(String environmentName); DBEnvironment createEnvironmentInstance(String requestedEnv); static DBEnvironment newEnvironmentInstance(String requestedEnv);  }
@Test public void newDbEnvironmentWithMissingDriverShouldRaiseSelfExplainingException() throws Exception { expectedEx.expectMessage("Cannot load " + SOME_ENVIRONMENT_NAME + " database driver " + NE_DRIVER_CLASS_NAME); factory.createEnvironmentInstance(SOME_ENVIRONMENT_NAME); }
@Test public void unsupportedEnvironmentInstantiationShouldRaiseException() throws Exception { expectedEx.expect(IllegalArgumentException.class); expectedEx.expectMessage("DB Environment not supported:" + NE_DB_ENVIRONMENT_NAME); factory.createEnvironmentInstance(NE_DB_ENVIRONMENT_NAME); }