DatabaseUtil { public static DbmsType dbmsTypeOf(DbmsHandlerComponent handler, Dbms dbms) { final String typeName = dbms.getTypeName(); return handler.findByName(typeName).orElseThrow(() -> new SpeedmentException( "Unable to find the database type " + typeName + ". The installed types are: " + handler.supportedDbmsTypes() .map(DbmsType::getName) .collect(joining(", ")) ) ); } private  DatabaseUtil(); static DbmsType dbmsTypeOf(DbmsHandlerComponent handler, Dbms dbms); static String findConnectionUrl(DbmsHandlerComponent dbmsHandlerComponent, Dbms dbms); static DbmsType findDbmsType(DbmsHandlerComponent dbmsHandlerComponent, Dbms dbms);  }
@Test void dbmsTypeOf() { final Dbms dbms = mock(Dbms.class); when(dbms.getTypeName()).thenReturn("dbms_type_name"); final Dbms dbms2 = mock(Dbms.class); when(dbms2.getTypeName()).thenReturn("non_existent_dbms_type_name"); final DbmsType dbmsType = mock(DbmsType.class); when(dbmsType.getName()).thenReturn("dbms_type_name"); final DbmsHandlerComponent dbmsHandlerComponent = mock(DbmsHandlerComponent.class); when(dbmsHandlerComponent.findByName("dbms_type_name")).thenReturn(Optional.of(dbmsType)); when(dbmsHandlerComponent.findByName("non_existent_dbms_type_name")).thenReturn(Optional.empty()); when(dbmsHandlerComponent.supportedDbmsTypes()).thenReturn(Stream.of(dbmsType)); assertNotNull(DatabaseUtil.dbmsTypeOf(dbmsHandlerComponent, dbms)); assertThrows(SpeedmentException.class, () -> DatabaseUtil.dbmsTypeOf(dbmsHandlerComponent, dbms2)); }