简体   繁体   English

Google Guava Predicates.or()或Predicates.and()类型

[英]Google Guava Predicates.or() or Predicates.and() type

In Guava, there is a utilities kind of method for Predicates class called 'or' or 'and', you can either pass a iterable or two predicates. 在Guava中,谓词类有一种实用程序方法,称为“或”或“和”,您可以传递一个可迭代的谓词或两个谓词。

I have a code example like below: 我有一个如下的代码示例:

class AccountNamePredicate implements Predicate<Account> {}
class AccountTypePredicate implements Predicate<Account> {}
class AccountManager {
    public Predicate<Account> getPredicate() {
         return Predicates.and(new AccountNamePredicate(), new AccountTypePredicate());
    }
}

My question is for the method getPredicate in AccountManager class, how can I test the method? 我的问题是AccountManager类中的getPredicate方法,如何测试该方法?

If I want to assert the return type of this method, how can I write the correct code. 如果要声明此方法的返回类型,如何编写正确的代码。 My assert statement below doesn't pass: 我的assert语句没有通过:

assertThat(getPredicate(), is(instanceOf(Predicate.class)));

Any idea about that? 有什么想法吗?

There is nothing to test in your scenario. 在您的方案中没有要测试的东西。 If you insist on test that you're testing the guava framework (guava development team already do that well) not your application. 如果您坚持要测试自己正在测试guava框架(guava开发团队已经做得很好),而不是您的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM