微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.junit.internal.matchers.TypeSafeMatcher的实例源码

项目:oscm    文件JavaMatchers.java   
/**
 * Checks if object has proper toString defined. This matcher can be
 * replaced with JUnit 4.8
 */
public static Matcher<Object> hasToString() {
    return new TypeSafeMatcher<Object>() {

        @Override
        public boolean matchesSafely(Object objectToTest) {
            try {
                objectToTest.getClass().getDeclaredMethod("toString");
            } catch (Exception e) {
                return false;
            }
            String s = objectToTest.toString();
            if (s == null || s.length() == 0) {
                return false;
            }
            return true;
        }

        @Override
        public void describeto(Description description) {
            description.appendText("proper toString()");
        }

    };
}
项目:oscm    文件JavaMatchers.java   
/**
 * Checks if array is non-empty. This matcher can be replaced with JUnit 4.8
 */
public static Matcher<Object[]> hasItemInArray() {
    return new TypeSafeMatcher<Object[]>() {

        @Override
        public boolean matchesSafely(Object[] arrayToTest) {
            if (arrayToTest == null || arrayToTest.length == 0) {
                return false;
            }
            return true;
        }

        @Override
        public void describeto(Description description) {
            description.appendText("non-empty array");
        }

    };
}
项目:oscm    文件JavaMatchers.java   
/**
 * Checks if list is non-empty. This matcher can be replaced with JUnit 4.8
 */
public static Matcher<Collection<?>> hasItems() {
    return new TypeSafeMatcher<Collection<?>>() {

        @Override
        public boolean matchesSafely(Collection<?> collection) {
            if (collection == null || collection.isEmpty()) {
                return false;
            }
            return true;
        }

        @Override
        public void describeto(Description description) {
            description.appendText("non-empty list");
        }

    };
}
项目:oscm    文件JavaMatchers.java   
/**
 * Checks if collection has the given number of items.
 */
public static Matcher<Collection<?>> hasItems(final int numberOfItems) {
    return new TypeSafeMatcher<Collection<?>>() {

        @Override
        public boolean matchesSafely(Collection<?> collection) {
            if (collection == null || collection.size() != numberOfItems) {
                return false;
            }
            return true;
        }

        @Override
        public void describeto(Description description) {
            description.appendText("expected a collection with "
                    + numberOfItems + " items");
        }

    };
}
项目:development    文件JavaMatchers.java   
/**
 * Checks if object has proper toString defined. This matcher can be
 * replaced with JUnit 4.8
 */
public static Matcher<Object> hasToString() {
    return new TypeSafeMatcher<Object>() {

        @Override
        public boolean matchesSafely(Object objectToTest) {
            try {
                objectToTest.getClass().getDeclaredMethod("toString");
            } catch (Exception e) {
                return false;
            }
            String s = objectToTest.toString();
            if (s == null || s.length() == 0) {
                return false;
            }
            return true;
        }

        @Override
        public void describeto(Description description) {
            description.appendText("proper toString()");
        }

    };
}
项目:development    文件JavaMatchers.java   
/**
 * Checks if array is non-empty. This matcher can be replaced with JUnit 4.8
 */
public static Matcher<Object[]> hasItemInArray() {
    return new TypeSafeMatcher<Object[]>() {

        @Override
        public boolean matchesSafely(Object[] arrayToTest) {
            if (arrayToTest == null || arrayToTest.length == 0) {
                return false;
            }
            return true;
        }

        @Override
        public void describeto(Description description) {
            description.appendText("non-empty array");
        }

    };
}
项目:development    文件JavaMatchers.java   
/**
 * Checks if list is non-empty. This matcher can be replaced with JUnit 4.8
 */
public static Matcher<Collection<?>> hasItems() {
    return new TypeSafeMatcher<Collection<?>>() {

        @Override
        public boolean matchesSafely(Collection<?> collection) {
            if (collection == null || collection.isEmpty()) {
                return false;
            }
            return true;
        }

        @Override
        public void describeto(Description description) {
            description.appendText("non-empty list");
        }

    };
}
项目:development    文件JavaMatchers.java   
/**
 * Checks if collection has the given number of items.
 */
public static Matcher<Collection<?>> hasItems(final int numberOfItems) {
    return new TypeSafeMatcher<Collection<?>>() {

        @Override
        public boolean matchesSafely(Collection<?> collection) {
            if (collection == null || collection.size() != numberOfItems) {
                return false;
            }
            return true;
        }

        @Override
        public void describeto(Description description) {
            description.appendText("expected a collection with "
                    + numberOfItems + " items");
        }

    };
}
项目:cassandra-kmean    文件sstableImportTest.java   
private static Matcher<UntypedResultSet.Row> withElements(final int key,final String v1,final int v2) {
    return new TypeSafeMatcher<UntypedResultSet.Row>()
    {
        @Override
        public boolean matchesSafely(Row input)
        {
            if (!input.has("k") || !input.has("v1") || !input.has("v2"))
                return false;
            return input.getInt("k") == key
                    && input.getString("v1").equals(v1)
                    && input.getInt("v2") == v2;
        }

        @Override
        public void describeto(Description description)
        {
            description.appendText(String.format("a row containing: %s,%s,%s",key,v1,v2));
        }
    };

}
项目:GraphTrek    文件sstableImportTest.java   
private static Matcher<UntypedResultSet.Row> withElements(final int key,v2));
        }
    };

}
项目:stratio-cassandra    文件sstableImportTest.java   
private static Matcher<UntypedResultSet.Row> withElements(final int key,v2));
        }
    };

}
项目:switchyard    文件SwitchYardExpectedException.java   
private Matcher<Throwable> hasMessage(final Matcher<String> matcher) {
    return new TypeSafeMatcher<Throwable>() {
        public void describeto(Description description) {
            description.appendText("exception with message ");
            description.appendDescriptionOf(matcher);
        }

        @Override
        public boolean matchesSafely(Throwable item) {
            final Throwable throwable = getCauseFromHandlerException(item);
            return matcher.matches(throwable.getMessage());
        }
    };
}
项目:opennmszh    文件DurationTest.java   
Matcher<Integer> isLessthan(final int val) {
    return new TypeSafeMatcher<Integer>() {

        @Override
        public boolean matchesSafely(Integer item) {
            return item < val;
        }

        public void describeto(Description descr) {
            descr.appendText("an integer less than ").appendValue(val);
        }
    };
}
项目:opennmszh    文件DurationTest.java   
Matcher<Integer> isGreaterThan(final int val) {
    return new TypeSafeMatcher<Integer>() {

        @Override
        public boolean matchesSafely(Integer item) {
            return item > val;
        }

        public void describeto(Description descr) {
            descr.appendText("an integer greater than ").appendValue(val);
        }
    };

}
项目:jability    文件AccesstypeUnitTest.java   
@Nonnull
protected static Matcher<Field> matchesOnly(@Nonnull final Accesstype accesstype) {
    return new TypeSafeMatcher<Field>() {
        @Override
        public boolean matchesSafely(Field item) {
            boolean result = true;
            for (Accesstype current : Accesstype.values()) {
                if (accesstype == current) {
                    if (!Accesstype.matches(item,current)) {
                        result = false;
                        break;
                    }
                } else {
                    if (Accesstype.matches(item,current)) {
                        result = false;
                        break;
                    }
                }
            }
            return result;
        }

        @Override
        public void describeto(Description description) {
            description.appendText("matches only ").appendValue(accesstype);
        }
    };
}
项目:OpenNMS    文件DurationTest.java   
Matcher<Integer> isLessthan(final int val) {
    return new TypeSafeMatcher<Integer>() {

        @Override
        public boolean matchesSafely(Integer item) {
            return item < val;
        }

        public void describeto(Description descr) {
            descr.appendText("an integer less than ").appendValue(val);
        }
    };
}
项目:OpenNMS    文件DurationTest.java   
Matcher<Integer> isGreaterThan(final int val) {
    return new TypeSafeMatcher<Integer>() {

        @Override
        public boolean matchesSafely(Integer item) {
            return item > val;
        }

        public void describeto(Description descr) {
            descr.appendText("an integer greater than ").appendValue(val);
        }
    };

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。