• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.csuite.testing;
18 
19 import com.google.common.truth.Correspondence;
20 
21 /**
22  * Useful implementations of {@link Correspondence}.
23  *
24  * <p>Correspondences are used with {@code IterableSubject.comparingElementsUsing(Correspondence)}
25  * and allow for making assertions on elements besides simple equality. See {@link Correspondence}
26  * for more information.
27  */
28 // TODO(hzalek): Move this into a dedicated testing library.
29 public final class Correspondences {
30 
31     private static final Correspondence<Object, Class<?>> INSTANCE_OF =
32             Correspondence.from(
33                     (Object obj, Class<?> clazz) -> {
34                         return clazz.isInstance(obj);
35                     },
36                     "is an instance of");
37 
38     /**
39      * Returns a {@link Correspondence} that determines whether elements are instances of the class
40      * they are compared to.
41      */
instanceOf()42     public static Correspondence<Object, Class<?>> instanceOf() {
43         return INSTANCE_OF;
44     }
45 
Correspondences()46     private Correspondences() {}
47 }
48