PoetMatchers.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:aws-sdk-java-v2 作者:
public static Matcher<ClassSpec> generatesTo(String expectedTestFile) {
    return new TypeSafeMatcher<ClassSpec>() {
        @Override
        protected boolean matchesSafely(ClassSpec spec) {
            String expectedClass = getExpectedClass(spec, expectedTestFile);
            String actualClass = generateClass(spec);
            try {
                assertThat(actualClass, equalToIgnoringWhiteSpace(expectedClass));
            } catch (AssertionError e) {
                //Unfortunately for string comparisons Hamcrest doesn't really give us a nice diff. On the other hand
                //IDEs know how to nicely display JUnit's ComparisonFailure - makes debugging tests much easier
                throw new ComparisonFailure(String.format("Output class does not match expected [test-file: %s]", expectedTestFile), expectedClass, actualClass);
            }
            return true;
        }

        @Override
        public void describeTo(Description description) {
            //Since we bubble an exception this will never actually get called
        }
    };
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号