use of com.google.common.testing.EqualsTester in project auto by google.
the class AutoValueTest method testGenericProperties.
@Test
public void testGenericProperties() throws Exception {
GenericProperties instance1 = GenericProperties.create(ImmutableMap.of("twenty-three", 23), ImmutableMap.of("very", (Map<String, Integer>) ImmutableMap.of("hairy", 17)));
GenericProperties instance2 = GenericProperties.create(ImmutableMap.of("seventeen", 17), ImmutableMap.of("very", (Map<String, Integer>) ImmutableMap.of("hairy", 23)));
new EqualsTester().addEqualityGroup(instance1).addEqualityGroup(instance2).testEquals();
assertEquals(ImmutableMap.of("very", (Map<String, Integer>) ImmutableMap.of("hairy", 23)), instance2.hairyMap());
}
use of com.google.common.testing.EqualsTester in project auto by google.
the class AutoValueTest method testSimple.
@Test
public void testSimple() throws Exception {
Simple instance1a = Simple.create("example", 23, ImmutableMap.of("twenty-three", 23L));
Simple instance1b = Simple.create("example", 23, ImmutableMap.of("twenty-three", 23L));
Simple instance2 = Simple.create("", 0, ImmutableMap.<String, Long>of());
assertEquals("example", instance1a.publicString());
assertEquals(23, instance1a.protectedInt());
assertEquals(ImmutableMap.of("twenty-three", 23L), instance1a.packageMap());
MoreObjects.ToStringHelper toStringHelper = MoreObjects.toStringHelper(Simple.class);
toStringHelper.add("publicString", "example");
toStringHelper.add("protectedInt", 23);
toStringHelper.add("packageMap", ImmutableMap.of("twenty-three", 23L));
assertEquals(toStringHelper.toString(), instance1a.toString());
new EqualsTester().addEqualityGroup(instance1a, instance1b).addEqualityGroup(instance2).testEquals();
}
use of com.google.common.testing.EqualsTester in project auto by google.
the class AutoAnnotationDefaultsTest method testDefaults.
@Test
public void testDefaults() throws Exception {
@EverythingWithDefaults
class Annotated {
}
EverythingWithDefaults expected = Annotated.class.getAnnotation(EverythingWithDefaults.class);
EverythingWithDefaults actual = newEverythingWithDefaults();
// Iterate over the annotation members to see if any differ. We could just compare expected and
// actual but if the comparison failed it could be hard to see exactly what differed.
StringBuilder differencesBuilder = new StringBuilder();
for (Method member : EverythingWithDefaults.class.getDeclaredMethods()) {
String name = member.getName();
Object expectedValue = member.invoke(expected);
Object actualValue = member.invoke(actual);
if (!equal(expectedValue, actualValue)) {
differencesBuilder.append("For ").append(name).append(" expected <").append(string(expectedValue)).append("> but was <").append(string(actualValue)).append(">\n");
}
}
String differences = differencesBuilder.toString();
assertTrue(differences, differences.isEmpty());
// All the members were the same. Check that the equals and hashCode results say so too.
new EqualsTester().addEqualityGroup(expected, actual).testEquals();
}
use of com.google.common.testing.EqualsTester in project guava by hceylan.
the class PredicatesTest method testIn_equality.
public void testIn_equality() {
Collection<Integer> nums = ImmutableSet.of(1, 5);
Collection<Integer> sameOrder = ImmutableSet.of(1, 5);
Collection<Integer> differentOrder = ImmutableSet.of(5, 1);
Collection<Integer> differentNums = ImmutableSet.of(1, 3, 5);
new EqualsTester().addEqualityGroup(Predicates.in(nums), Predicates.in(nums), Predicates.in(sameOrder), Predicates.in(differentOrder)).addEqualityGroup(Predicates.in(differentNums)).testEquals();
}
use of com.google.common.testing.EqualsTester in project guava by hceylan.
the class FunctionsTest method testForMapWithoutDefault.
public void testForMapWithoutDefault() {
Map<String, Integer> map = Maps.newHashMap();
map.put("One", 1);
map.put("Three", 3);
map.put("Null", null);
Function<String, Integer> function = Functions.forMap(map);
assertEquals(1, function.apply("One").intValue());
assertEquals(3, function.apply("Three").intValue());
assertNull(function.apply("Null"));
try {
function.apply("Two");
fail();
} catch (IllegalArgumentException expected) {
}
new EqualsTester().addEqualityGroup(function, Functions.forMap(map)).addEqualityGroup(Functions.forMap(map, 42)).testEquals();
}
Aggregations