DatabaseUtil { public static DbmsType findDbmsType(DbmsHandlerComponent dbmsHandlerComponent, Dbms dbms) { return dbmsHandlerComponent.findByName(dbms.getTypeName()) .orElseThrow(() -> new SpeedmentException( "Could not find any installed DbmsType named '" + dbms.getTypeName() + "'." )); } 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 findDbmsType() { 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()); assertNotNull(DatabaseUtil.findDbmsType(dbmsHandlerComponent, dbms)); assertThrows(SpeedmentException.class, () -> DatabaseUtil.findDbmsType(dbmsHandlerComponent, dbms2)); }