You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2018/05/31 03:41:00 UTC

[jira] [Created] (GROOVY-8617) Bug with Spock and where clause

Paul King created GROOVY-8617:
---------------------------------

             Summary: Bug with Spock and where clause
                 Key: GROOVY-8617
                 URL: https://issues.apache.org/jira/browse/GROOVY-8617
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 2.5.0
            Reporter: Paul King


This was from trying to port Griffon to 2.5.0:
{code}
@Grab("org.spockframework:spock-core:1.2-groovy-2.4-SNAPSHOT")
@Grab("org.codehaus.griffon:griffon-javafx:2.14.0")
@GrabResolver("https://oss.sonatype.org/content/repositories/snapshots/")

import griffon.javafx.beans.binding.*
import groovy.transform.Canonical
import javafx.beans.binding.Binding
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import spock.lang.Specification
import spock.lang.Unroll

import java.util.function.Predicate

@Unroll
class FilteringBindingsSpec extends Specification {
    def "Filter then findFirst in list with defaultValue"() {
given:
        Box defaultValue = new Box(6)
        ObservableList<Box> items = FXCollections.observableArrayList()
        Predicate<Box> filter = { it.id % 2 == 0 }
        Binding binding = FilteringBindings.filterThenFindFirst(items, defaultValue, filter)

        expect:
        defaultValue == binding.get()

        when:
        items.addAll([new Box(1), new Box(2), new Box(3), new Box(4)])

        then:
        new Box(2) == binding.get()
    }

    def "Filter then findFirst #type in list with defaultValue"() {
        given:
        ObservableList items = FXCollections.observableArrayList()
        Binding binding = FilteringBindings."filterThenFindFirst${type}"(items, defaultValue, predicate)

        expect:
        defaultValue == binding.get()

        when:
        items.addAll(values)

        then:
        result == binding.get()

        where:
        type      | defaultValue | predicate                   | values                    | result
        'Boolean' | true         | { it }                      | [false, true, false]      | true
        'Integer' | 6            | { it % 2 == 0 }             | [1, 2, 3, 4, 5]           | 2
    }

    @Canonical
    private static class Box {
        int id
    }
}
{code}
JUnit 4 Runner, Tests: 1, Failures: 2, Time: 175
Test Failure: Filter then findFirst #type in list with defaultValue(FilteringBindingsSpec)
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'true' with class 'java.lang.Boolean' to class 'FilteringBindingsSpec$Box'
    at FilteringBindingsSpec.Filter then findFirst #type in list with defaultValue(ConsoleScript0:49)

Test Failure: Filter then findFirst #type in list with defaultValue(FilteringBindingsSpec)
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '6' with class 'java.lang.Integer' to class 'FilteringBindingsSpec$Box'
    at FilteringBindingsSpec.Filter then findFirst #type in list with defaultValue(ConsoleScript0:49)

Apparently there's some state left from the first feature method that leaks into the second and third. This does not occur with Groovy 2.4.15 and Spock 1.1-groovy-2.4




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)