use of com.google.common.testing.EqualsTester in project guava by google.
the class SubscriberTest method testEquals.
public void testEquals() throws Exception {
Method charAt = String.class.getMethod("charAt", int.class);
Method concat = String.class.getMethod("concat", String.class);
new EqualsTester().addEqualityGroup(Subscriber.create(bus, "foo", charAt), Subscriber.create(bus, "foo", charAt)).addEqualityGroup(Subscriber.create(bus, "bar", charAt)).addEqualityGroup(Subscriber.create(bus, "foo", concat)).testEquals();
}
use of com.google.common.testing.EqualsTester in project core-java by SpineEventEngine.
the class QueryParameterShould method support_equality.
@Test
public void support_equality() {
final String param1 = "param1";
final String param2 = "param2";
final String foobar = "foobar";
final String baz = "baz";
final StringValue foobarValue = StringValue.newBuilder().setValue(foobar).build();
final QueryParameter parameter1 = eq(param1, foobar);
final QueryParameter parameter2 = eq(param1, foobarValue);
final QueryParameter parameter3 = eq(param1, baz);
final QueryParameter parameter4 = eq(param2, foobar);
new EqualsTester().addEqualityGroup(parameter1, parameter2).addEqualityGroup(parameter3).addEqualityGroup(parameter4).testEquals();
}
use of com.google.common.testing.EqualsTester in project core-java by SpineEventEngine.
the class AbstractVersionableEntityShould method have_equals.
@SuppressWarnings("MagicNumber")
@Test
public void have_equals() throws Exception {
final AvEntity entity = new AvEntity(88L);
final AvEntity another = new AvEntity(88L);
another.updateState(entity.getState(), entity.getVersion());
new EqualsTester().addEqualityGroup(entity, another).addEqualityGroup(new AvEntity(42L)).testEquals();
}
use of com.google.common.testing.EqualsTester in project alluxio by Alluxio.
the class CommonTestUtils method testEquals.
/**
* Uses reflection to test the equals and hashCode methods for the given simple java object.
*
* It is required that the given class has a no-arg constructor.
*
* Note: To use this method to test a class which contains a final non-enum class as a field, the
* class must either have a no-arg constructor, or you must prepare the final class for testing.
* See the top of {@link CommonTestUtilsTest} for an example.
*
* @param clazz the class to test the equals and hashCode methods for
* @param excludedFields names of fields which should not impact equality
*/
public static <T> void testEquals(Class<T> clazz, String... excludedFields) {
Set<String> excludedFieldsSet = new HashSet<>(Arrays.asList(excludedFields));
EqualsTester equalsTester = new EqualsTester();
equalsTester.addEqualityGroup(createBaseObject(clazz), createBaseObject(clazz));
// For each non-excluded field, create an object of the class with only that field changed.
for (Field field : getNonStaticFields(clazz)) {
if (excludedFieldsSet.contains(field.getName())) {
continue;
}
field.setAccessible(true);
T instance = createBaseObject(clazz);
try {
field.set(instance, getValuesForFieldType(field.getType()).get(1));
} catch (Exception e) {
throw Throwables.propagate(e);
}
equalsTester.addEqualityGroup(instance);
}
equalsTester.testEquals();
}
use of com.google.common.testing.EqualsTester in project beam by apache.
the class PCollectionTupleTest method testEquals.
@Test
public void testEquals() {
TestPipeline p = TestPipeline.create();
TupleTag<Long> longTag = new TupleTag<>();
PCollection<Long> longs = p.apply(GenerateSequence.from(0));
TupleTag<String> strTag = new TupleTag<>();
PCollection<String> strs = p.apply(Create.of("foo", "bar"));
EqualsTester tester = new EqualsTester();
// Empty tuples in the same pipeline are equal
tester.addEqualityGroup(PCollectionTuple.empty(p), PCollectionTuple.empty(p));
tester.addEqualityGroup(PCollectionTuple.of(longTag, longs).and(strTag, strs), PCollectionTuple.of(longTag, longs).and(strTag, strs));
tester.addEqualityGroup(PCollectionTuple.of(longTag, longs));
tester.addEqualityGroup(PCollectionTuple.of(strTag, strs));
TestPipeline otherPipeline = TestPipeline.create();
// Empty tuples in different pipelines are not equal
tester.addEqualityGroup(PCollectionTuple.empty(otherPipeline));
tester.testEquals();
}
Aggregations