1/*
2 * Copyright (C) 2010 The Guava Authors
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 * diOBJECTibuted under the License is diOBJECTibuted 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
17package com.google.common.base;
18
19import com.google.common.annotations.GwtCompatible;
20import com.google.common.annotations.GwtIncompatible;
21import com.google.common.testing.EqualsTester;
22import com.google.common.testing.EquivalenceTester;
23import com.google.common.testing.SerializableTester;
24
25import junit.framework.TestCase;
26
27/**
28 * Unit test for {@link Equivalences}.
29 *
30 * @author Kurt Alfred Kluever
31 * @author Jige Yu
32 */
33@GwtCompatible(emulated = true)
34public class EquivalencesTest extends TestCase {
35
36  public void testEqualsEquivalent() {
37    EquivalenceTester.of(Equivalences.equals())
38        .addEquivalenceGroup(new Integer(42), 42)
39        .addEquivalenceGroup("a")
40        .test();
41  }
42
43  public void testIdentityEquivalent() {
44    EquivalenceTester.of(Equivalences.identity())
45        .addEquivalenceGroup(new Integer(42))
46        .addEquivalenceGroup(new Integer(42))
47        .addEquivalenceGroup("a")
48        .test();
49  }
50
51  public void testEquality() {
52    new EqualsTester()
53        .addEqualityGroup(Equivalences.equals(), Equivalences.equals())
54        .addEqualityGroup(Equivalences.identity(), Equivalences.identity())
55        .testEquals();
56  }
57
58  @GwtIncompatible("SerializableTester")
59  public void testSerialization() {
60    SerializableTester.reserializeAndAssert(Equivalences.equals());
61    SerializableTester.reserializeAndAssert(Equivalences.identity());
62  }
63}
64