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 bazel by bazelbuild.
the class WorkerPoolConfigTest method testEquals.
@Test
public void testEquals() throws Exception {
WorkerPoolConfig config1a = new WorkerPoolConfig();
config1a.setLifo(true);
config1a.setMaxIdlePerKey(4);
config1a.setMaxTotalPerKey(4);
config1a.setMinIdlePerKey(4);
config1a.setMaxTotal(-1);
config1a.setBlockWhenExhausted(true);
config1a.setTestOnBorrow(true);
config1a.setTestOnCreate(false);
config1a.setTestOnReturn(true);
config1a.setTimeBetweenEvictionRunsMillis(-1);
WorkerPoolConfig config1b = new WorkerPoolConfig();
config1b.setLifo(true);
config1b.setMaxIdlePerKey(4);
config1b.setMaxTotalPerKey(4);
config1b.setMinIdlePerKey(4);
config1b.setMaxTotal(-1);
config1b.setBlockWhenExhausted(true);
config1b.setTestOnBorrow(true);
config1b.setTestOnCreate(false);
config1b.setTestOnReturn(true);
config1b.setTimeBetweenEvictionRunsMillis(-1);
WorkerPoolConfig config2a = new WorkerPoolConfig();
config2a.setLifo(true);
config2a.setMaxIdlePerKey(1);
config2a.setMaxTotalPerKey(1);
config2a.setMinIdlePerKey(1);
config2a.setMaxTotal(-1);
config2a.setBlockWhenExhausted(true);
config2a.setTestOnBorrow(true);
config2a.setTestOnCreate(false);
config2a.setTestOnReturn(true);
config2a.setTimeBetweenEvictionRunsMillis(-1);
WorkerPoolConfig config2b = new WorkerPoolConfig();
config2b.setLifo(true);
config2b.setMaxIdlePerKey(1);
config2b.setMaxTotalPerKey(1);
config2b.setMinIdlePerKey(1);
config2b.setMaxTotal(-1);
config2b.setBlockWhenExhausted(true);
config2b.setTestOnBorrow(true);
config2b.setTestOnCreate(false);
config2b.setTestOnReturn(true);
config2b.setTimeBetweenEvictionRunsMillis(-1);
new EqualsTester().addEqualityGroup(config1a, config1b).addEqualityGroup(config2a, config2b).testEquals();
}
use of com.google.common.testing.EqualsTester in project glide by bumptech.
the class KeyAssertions method assertDifferent.
public static void assertDifferent(Key first, Key second, boolean checkDiskCacheKey) throws NoSuchAlgorithmException {
new EqualsTester().addEqualityGroup(first).addEqualityGroup(second).testEquals();
if (checkDiskCacheKey) {
MessageDigest firstDigest = MessageDigest.getInstance("SHA-1");
first.updateDiskCacheKey(firstDigest);
MessageDigest secondDigest = MessageDigest.getInstance("SHA-1");
second.updateDiskCacheKey(secondDigest);
assertThat(getDigest(first)).isNotEqualTo(getDigest(second));
}
}
Aggregations