[MAGNOLIA-6813] Add hasChildWhich node matcher Created: 11/Oct/16  Updated: 21/Nov/16  Resolved: 07/Nov/16

Status: Closed
Project: Magnolia
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Neutral
Reporter: Maxime Michel Assignee: Unassigned
Resolution: Won't Do Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:
Sprint: Basel 70
Story Points: 3

 Description   

The following matcher is seen in multiple projects:

  • rest-tools
  • resources
  • UI
  • templating-samples
    private Matcher<? super Node> hasChildWhich(final Matcher<Node> matcher) {
        return new TypeSafeMatcher<Node>() {
            @Override
            protected boolean matchesSafely(Node node) {
                try {
                    return NodeUtil.getNodes(node, o -> matcher.matches(o)).iterator().hasNext();
                } catch (RepositoryException e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            public void describeTo(Description description) {
                description.appendText("a node with a child with ");
                matcher.describeTo(description);
            }
        };
    }

It would be nice to add it to our collection and use it from there directly.



 Comments   
Comment by Mikaël Geljić [ 31/Oct/16 ]

Enlighten me, taking example from AdmincentralModuleVersionHandlerTest: how different is it from using the hasNode matcher?

assertThat(securityBaseAclUri, not(hasNode(hasProperty("path", "/.magnolia/pages/jcrUtils*"))));
Comment by Mikaël Geljić [ 07/Nov/16 ]

Thanks for the prompt response, closing as won't do.

Comment by Maxime Michel [ 10/Nov/16 ]

Not being any of the authors of hasChildWhich myself, I asked fgrilli to take a look at your comment when you posted it. He said your solution seems appropriate. Therefore, I was thinking of getting rid of that method in the modules I mentioned, replacing it with your solution, in order to prevent further propagation & make the team aware. I haven't had time / forgot to post that. Also, I'm not sure it is worth the effort.

Comment by Mikaël Geljić [ 10/Nov/16 ]

No worries, indeed it's not a big deal. On the other hand trimming the living examples of it should be a fairly cheep QA commit

Comment by Maxime Michel [ 10/Nov/16 ]

I'll take care of that after the release.

Generated at Mon Feb 12 04:18:04 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.