Search in sources :

Example 1 with EqualsTester

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();
}
Also used : QueryParameter(io.spine.client.QueryParameter) EqualsTester(com.google.common.testing.EqualsTester) String(java.lang.String) Matchers.containsString(org.hamcrest.Matchers.containsString) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 2 with EqualsTester

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();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 3 with EqualsTester

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();
}
Also used : Field(java.lang.reflect.Field) EqualsTester(com.google.common.testing.EqualsTester) HashSet(java.util.HashSet)

Example 4 with EqualsTester

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();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 5 with EqualsTester

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));
    }
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) MessageDigest(java.security.MessageDigest)

Aggregations

EqualsTester (com.google.common.testing.EqualsTester)225 Test (org.junit.Test)118 GwtIncompatible (com.google.common.annotations.GwtIncompatible)10 ParameterizedType (java.lang.reflect.ParameterizedType)10 Test (org.junit.jupiter.api.Test)9 WildcardType (java.lang.reflect.WildcardType)8 Method (java.lang.reflect.Method)7 Entry (java.util.Map.Entry)7 GenericArrayType (java.lang.reflect.GenericArrayType)6 Type (java.lang.reflect.Type)6 HashMap (java.util.HashMap)6 ImmutableList (com.google.common.collect.ImmutableList)5 Path (com.google.devtools.build.lib.vfs.Path)5 List (java.util.List)5 DisplayName (org.junit.jupiter.api.DisplayName)5 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Label (com.google.devtools.build.lib.cmdline.Label)3