Force Spock to raise error [Exception]

ServiceImpl


    def "Abnormal system"() {
        setup:
//        service.createBody(_ as boolean) >> { throw new RuntimeException("dummy") }
        service.createBody(_) >> { throw new RuntimeException("dummy") }

        
        when:
        String testString = service.send(to, hash)

        then:
        RuntimeException e = thrown()
        e.getMessage() == expected

        where:
        testcase | to          | hash       | expected
        "test"   | "[email protected]" | "testhash" | "dummy"

    }

In IntelliJ, the _ part of service.createBody (\ _) turned yellow and I always complemented it. If only _ is used, an Exception will be generated. Is it special when boolean? It may be useful to remember when you want to force an Exception

Recommended Posts

Force Spock to raise error [Exception]
Error: Error converting bytecode to dex: Cause: java.lang.RuntimeException: Exception parsing classes