|
Java example source code file (EquivalenceTester.java)
The EquivalenceTester.java Java example source code/* * Copyright (C) 2011 The Guava Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.testing; import static com.google.common.base.Preconditions.checkNotNull; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import com.google.common.annotations.Beta; import com.google.common.annotations.GwtCompatible; import com.google.common.base.Equivalence; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.testing.RelationshipTester.ItemReporter; import java.util.List; /** * Tester for {@link Equivalence} relationships between groups of objects. * * <p> * To use, create a new {@link EquivalenceTester} and add equivalence groups * where each group contains objects that are supposed to be equal to each * other. Objects of different groups are expected to be unequal. For example: * * <pre> * {@code * EquivalenceTester.of(someStringEquivalence) * .addEquivalenceGroup("hello", "h" + "ello") * .addEquivalenceGroup("world", "wor" + "ld") * .test(); * } * </pre> * * <p> * Note that testing {@link Object#equals(Object)} is more simply done using * the {@link EqualsTester}. It includes an extra test against an instance of an * arbitrary class without having to explicitly add another equivalence group. * * @author Gregory Kick * @since 10.0 * * TODO(gak): turn this into a test suite so that each test can fail * independently */ @Beta @GwtCompatible public final class EquivalenceTester<T> { private static final int REPETITIONS = 3; private final Equivalence<? super T> equivalence; private final RelationshipTester<T> delegate; private final List<T> items = Lists.newArrayList(); private EquivalenceTester(Equivalence<? super T> equivalence) { this.equivalence = checkNotNull(equivalence); this.delegate = new RelationshipTester<T>( equivalence, "equivalent", "hash", new ItemReporter()); } public static <T> EquivalenceTester Other Java examples (source code examples)Here is a short list of links related to this Java EquivalenceTester.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.