### Question:
DatabaseDialectDetector { public static String autoDetectDatabaseDialect(String url) { if (url == null) { return null; } if (url.contains(":oracle:")) { return "oracle"; } if (url.contains(":hsqldb:")) { return "hsqldb"; } if (url.contains(":mysql:")) { return "mysql"; } if (url.contains(":db2:")) { return "db2"; } if (url.contains(":postgresql:")) { return "postgresql"; } if (url.contains(":derby:")) { return "derby"; } if (url.contains(":sqlserver:")) { return "mssql"; } return null; }  static String autoDetectDatabaseDialect(String url);  }### Answer:
@Test void derby() { String dialect = DatabaseDialectDetector.autoDetectDatabaseDialect("jdbc:derby:test;create=true"); assertEquals("derby", dialect); }
@Test void mssql() { String dialect = DatabaseDialectDetector.autoDetectDatabaseDialect("jdbc:sqlserver: assertEquals("mssql", dialect); }
@Test void nullUrl() { String dialect = DatabaseDialectDetector.autoDetectDatabaseDialect(null); assertNull(dialect); }
@Test void unknownDialect() { String dialect = DatabaseDialectDetector.autoDetectDatabaseDialect("xxxxx"); assertNull(dialect); }
@Test void oracle() { String dialect = DatabaseDialectDetector.autoDetectDatabaseDialect("jdbc:oracle:thin:@localhost:1521:XE"); assertEquals("oracle", dialect); }
@Test void hsqldb() { String dialect = DatabaseDialectDetector.autoDetectDatabaseDialect("jdbc:hsqldb:mem:unitils"); assertEquals("hsqldb", dialect); }
@Test void mysql() { String dialect = DatabaseDialectDetector.autoDetectDatabaseDialect("jdbc:mysql: assertEquals("mysql", dialect); }
@Test void db2() { String dialect = DatabaseDialectDetector.autoDetectDatabaseDialect("jdbc:db2:TEST"); assertEquals("db2", dialect); }
@Test void postgresql() { String dialect = DatabaseDialectDetector.autoDetectDatabaseDialect("jdbc:postgresql:test"); assertEquals("postgresql", dialect); }