Check results of spread operator with startsWith or like











up vote
0
down vote

favorite












Let's say I have:



class Conflict extends RuntimeException {
Conflict(String message) {
super(message)
}
}


and



class Conflicts extends RuntimeException {

List<Conflict> conflicts = new ArrayList<>()

Conflicts(List<Conflict> conflicts) {
this.conflicts = conflicts
}
}


In Spock, I typically check exception messages with spread operator:



def e = thrown(Conflicts)
e.conflicts*.message == ["my expected message 1", "my expected message 2"]


Is there any way how to check startsWith, like and other operations in similar succinct way in Groovy?










share|improve this question






















  • Maybe: ["my expected message 1", "my expected message 2"].every { it.contains('expected') }?
    – Opal
    Nov 7 at 12:19










  • e.conflicts*.message.findAll{it=~"my expected message 1|my expected message 2"}
    – daggett
    Nov 7 at 12:31















up vote
0
down vote

favorite












Let's say I have:



class Conflict extends RuntimeException {
Conflict(String message) {
super(message)
}
}


and



class Conflicts extends RuntimeException {

List<Conflict> conflicts = new ArrayList<>()

Conflicts(List<Conflict> conflicts) {
this.conflicts = conflicts
}
}


In Spock, I typically check exception messages with spread operator:



def e = thrown(Conflicts)
e.conflicts*.message == ["my expected message 1", "my expected message 2"]


Is there any way how to check startsWith, like and other operations in similar succinct way in Groovy?










share|improve this question






















  • Maybe: ["my expected message 1", "my expected message 2"].every { it.contains('expected') }?
    – Opal
    Nov 7 at 12:19










  • e.conflicts*.message.findAll{it=~"my expected message 1|my expected message 2"}
    – daggett
    Nov 7 at 12:31













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Let's say I have:



class Conflict extends RuntimeException {
Conflict(String message) {
super(message)
}
}


and



class Conflicts extends RuntimeException {

List<Conflict> conflicts = new ArrayList<>()

Conflicts(List<Conflict> conflicts) {
this.conflicts = conflicts
}
}


In Spock, I typically check exception messages with spread operator:



def e = thrown(Conflicts)
e.conflicts*.message == ["my expected message 1", "my expected message 2"]


Is there any way how to check startsWith, like and other operations in similar succinct way in Groovy?










share|improve this question













Let's say I have:



class Conflict extends RuntimeException {
Conflict(String message) {
super(message)
}
}


and



class Conflicts extends RuntimeException {

List<Conflict> conflicts = new ArrayList<>()

Conflicts(List<Conflict> conflicts) {
this.conflicts = conflicts
}
}


In Spock, I typically check exception messages with spread operator:



def e = thrown(Conflicts)
e.conflicts*.message == ["my expected message 1", "my expected message 2"]


Is there any way how to check startsWith, like and other operations in similar succinct way in Groovy?







groovy spock






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 7 at 12:05









Patrik Mihalčin

5462925




5462925












  • Maybe: ["my expected message 1", "my expected message 2"].every { it.contains('expected') }?
    – Opal
    Nov 7 at 12:19










  • e.conflicts*.message.findAll{it=~"my expected message 1|my expected message 2"}
    – daggett
    Nov 7 at 12:31


















  • Maybe: ["my expected message 1", "my expected message 2"].every { it.contains('expected') }?
    – Opal
    Nov 7 at 12:19










  • e.conflicts*.message.findAll{it=~"my expected message 1|my expected message 2"}
    – daggett
    Nov 7 at 12:31
















Maybe: ["my expected message 1", "my expected message 2"].every { it.contains('expected') }?
– Opal
Nov 7 at 12:19




Maybe: ["my expected message 1", "my expected message 2"].every { it.contains('expected') }?
– Opal
Nov 7 at 12:19












e.conflicts*.message.findAll{it=~"my expected message 1|my expected message 2"}
– daggett
Nov 7 at 12:31




e.conflicts*.message.findAll{it=~"my expected message 1|my expected message 2"}
– daggett
Nov 7 at 12:31












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










You can use every for that:



def e = thrown(Conflicts)
e.conflicts*.message.every { it.startsWith("my expected message" }





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189143%2fcheck-results-of-spread-operator-with-startswith-or-like%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    You can use every for that:



    def e = thrown(Conflicts)
    e.conflicts*.message.every { it.startsWith("my expected message" }





    share|improve this answer

























      up vote
      1
      down vote



      accepted










      You can use every for that:



      def e = thrown(Conflicts)
      e.conflicts*.message.every { it.startsWith("my expected message" }





      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        You can use every for that:



        def e = thrown(Conflicts)
        e.conflicts*.message.every { it.startsWith("my expected message" }





        share|improve this answer












        You can use every for that:



        def e = thrown(Conflicts)
        e.conflicts*.message.every { it.startsWith("my expected message" }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 8 at 21:19









        Michael

        1,0331712




        1,0331712






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189143%2fcheck-results-of-spread-operator-with-startswith-or-like%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Academy of Television Arts & Sciences

            L'Équipe

            1995 France bombings