public static String getDatabaseName(final SQLStatement sqlStatement, final String currentDatabaseName) {
        Optional<DatabaseSegment> databaseSegment = sqlStatement instanceof FromDatabaseAvailable ? ((FromDatabaseAvailable) sqlStatement).getDatabase() : Optional.empty();
        return databaseSegment.map(optional -> optional.getIdentifier().getValue()).orElse(currentDatabaseName);
    }
@Test
    void assertDatabaseNameWhenAvailableInSQLStatement() {
        FromDatabaseAvailable sqlStatement = mock(FromDatabaseAvailable.class, withSettings().extraInterfaces(SQLStatement.class));
        DatabaseSegment databaseSegment = mock(DatabaseSegment.class, RETURNS_DEEP_STUBS);
        when(databaseSegment.getIdentifier().getValue()).thenReturn("bar_db");
        when(sqlStatement.getDatabase()).thenReturn(Optional.of(databaseSegment));
        assertThat(DatabaseNameUtils.getDatabaseName((SQLStatement) sqlStatement, "foo_db"), is("bar_db"));
    }