Hi Tommy,

This works:

class Library {
    boolean someLibraryMethod() {
        throw new RuntimeException("'" + "LAZY DEVELOPER! This is a test" + "'")
    }
    boolean someOtherLibraryMethod() {
        throw new RuntimeException("'LAZY DEVELOPER! This is a test'")
    }
}

class LibraryTest extends Specification {

    def lib = new Library()

    def "someLibraryMethod returns true"() {
        when:
        def result = lib.someLibraryMethod()

        then:
        def e = thrown(RuntimeException)
        e.message == "'" + "LAZY DEVELOPER! This is a test" + "'"
        e.message == "'LAZY DEVELOPER! This is a test'"
    }

    def "someOtherLibraryMethod returns true"() {
        when:
        def result = lib.someOtherLibraryMethod()

        then:
        def e = thrown(RuntimeException)
        e.message == "'" + "LAZY DEVELOPER! This is a test" + "'"
        e.message == "'LAZY DEVELOPER! This is a test'"
    }
}

With Java 21 (21.0.3-tem) and Groovy 4.0.21

Look at this repo I've created for you

https://github.com/sbglasius/groovy-exception-experiment




Den man. 13. maj 2024 kl. 18.45 skrev Tommy Svensson <to...@natusoft.se>:

> Here is a test I have been forced to comment out since it is 100%
> impossible to make work due to  '  character keeps getting removed!
>
>         assert se3.message == "'" +"LAZY DEVELOPER! This is a test" + "'"
>
>
>             No matter what you do here the result will be:
>
>                 Assertion failed:
>
>                 assert se3.message == "'" +"LAZY DEVELOPER! This is a
> test" + "'"
>                        |   |
>                        |   'LAZY DEVELOPER! This is a Test'
>                        LAZY DEVELOPER! This is a Test
>
>              That is the "'" character will be removed in the constant
> comparison text
>              and thus the test will always fail, not matter what I do!!!
>
> Any suggestions ?
>
> I'm using release 21 of Groovy.
>
> ______________________
>
> Tommy Svensson
>
> to...@natusoft.se
>
>
>
>

-- 

Med venlig hilsen,
Søren Berg Glasius

Hedevej 1, Gl. Rye, 8680 Ry
Mobile: +45 40 44 91 88
--- Press ESC once to quit - twice to save the changes.

Reply via email to