Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom matching with cyclic references requires ignoring the custom-matched field #31

Open
nieldw opened this issue Jan 11, 2019 · 0 comments

Comments

@nieldw
Copy link

nieldw commented Jan 11, 2019

Related to #16

Custom matching in an object with cyclic references requires ignoring the custom-matched field, otherwise it will fail.

Example:

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

import static com.shazam.shazamcrest.MatcherAssert.assertThat;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
import static org.hamcrest.CoreMatchers.equalTo;

public class CustomMatcherWithCyclicDepsTest {
    class MyClass {
        private List<MyClass> myClasses;
        private String name;

        MyClass(String name) {
            this.name = name;
        }

        void setMyClasses(List<MyClass> myClasses) {
            this.myClasses = myClasses;
        }
    }

    @Test
    void testCustomMatching_inParent() {
        MyClass expectedChild = new MyClass("child");
        MyClass expected = new MyClass("name-matched-by-custom");
        expected.setMyClasses(Arrays.asList(expected, expectedChild));

        MyClass actualChild = new MyClass("child");
        MyClass actual = new MyClass("parent");
        actual.setMyClasses(Arrays.asList(actual, actualChild));

        assertThat(actual, sameBeanAs(expected)
                .with("name", equalTo("parent"))

                // Test only passes with this
                .ignoring("0x1.name"));
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant