Re: String comparison tests on exception messages keep failing due to >'< character keeps getting removed!

Søren Berg Glasius <soeren-Kc6N1ySXURF/[email protected]>
Newsgroups gmane.comp.lang.groovy.user
Message-ID <CAGY+WWTmj6Lv8LNSKQURN4FA9jS1M0tn1_GZwsi-sJb2O-8e7w@mail.gmail.com>
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 <[email protected]>:

> 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
>
> [email protected]
>
>
>
>

-- 

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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.