### Question:
JdbcDriverServiceImpl implements JdbcDriverService, ApplicationContextAware { @Override public synchronized void setDriverMappingAndRegister(String driverClass, String path) throws Exception { ClassLoader classLoader = getClassLoaderAndVerifyDriverClassName(driverClass, path); String registeredUrl = getUrlByDriverClassName(driverClass); if (SYSTEM_CLASSLOADER_PATH.equals(registeredUrl)) { unRegisterByClassName(driverClass); } else { unRegisterByUrl(registeredUrl); } driverClassToUrlMap.put(driverClass, path); classLoaderToUrlMap.put(classLoader, path); register(driverClass); if (getPropertiesManagementService() != null) { String driverNameKey = String.format(SYSTEM_PROPERTIES_LIST_KEY_FORMAT, driverClass); getPropertiesManagementService().setProperty(driverNameKey, path); } }  void setRepository(RepositoryService repository); void setSystemClassLoaderFirst(Boolean systemClassLoaderFirst); void setJdbcDriversFolder(String jdbcDriversFolder); String getJdbcDriversFolder(); @Override synchronized void register(String driverClass); @Override synchronized boolean isRegistered(String driverClass); @Override synchronized void setDriverMappings(Map<String, String> driverMappings); synchronized void setDriverMapping(String driverClass, String path); synchronized void removeDriverMapping(String driverClass); @Override Map<String, String> getDriverMappings(); @Override Set<String> getRegisteredDriverClassNames(); @Override synchronized void setDriverMappingAndRegister(String driverClass, String path); @Override @Transactional(propagation = Propagation.REQUIRED) void setDriver(String driverClassName, Map<String, byte[]> driverFiles); @Override void setApplicationContext(ApplicationContext applicationContext); static final String DEFAULT_JDBC_REPO_FOLDER; static final String DEFAULT_JDBC_TEMP_FOLDER; static final String URL_CLASSLOADER_FORMAT; static final String TEMP_FILE_PATH_FORMAT; static final String SYSTEM_PROPERTIES_LIST_KEY_PREFIX; static final String SYSTEM_PROPERTIES_LIST_KEY_FORMAT; static final String SYSTEM_PROPERTIES_PRESERVED_KEY_SUFFIX; static final String SYSTEM_CLASSLOADER_PATH; }### Answer:
@Test public void setDriverMappingAndRegisterShouldRegisterDriverAndSetMappingAndUpdateGlobalProperties() throws Exception { mockJars("/jdbc/testjdbcdriver", "testjdbcdriver.jar"); jdbcDriverService.setDriverMappingAndRegister(TEST_DRIVER_CLASS_NAME, "testjdbcdriver"); assertEquals(1, driversSet.size()); Driver driver = driversSet.iterator().next(); assertTrue(driver instanceof JdbcDriverShim); Class<? extends Driver> registeredDriverClass = ((JdbcDriverShim)driver).getDriver().getClass(); assertEquals(TEST_DRIVER_CLASS_NAME, registeredDriverClass.getName()); assertFalse(TestJdbcDriver.class.equals(registeredDriverClass)); assertEquals(1, propertiesManagementServiceProps.size()); assertEquals(String.format(JdbcDriverServiceImpl.SYSTEM_PROPERTIES_LIST_KEY_FORMAT, TEST_DRIVER_CLASS_NAME), propertiesManagementServiceProps.keySet().iterator().next()); assertEquals("testjdbcdriver", propertiesManagementServiceProps.values().iterator().next()); }
@Test public void setDriverMappingAndRegisterShouldNotSetMappingAndUpdateGlobalPropertiesIfExceptionOccurs() throws Exception { try { jdbcDriverService.setDriverMappingAndRegister(TEST_DRIVER_CLASS_NAME + "1", "testjdbcdriver"); fail("Exception was not thrown"); } catch (Exception e) { assertEquals(0, driversSet.size()); assertEquals(0, propertiesManagementServiceProps.size()); } }