1 /* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockito.internal.matchers; 6 7 import org.junit.Test; 8 import org.mockitoutil.TestBase; 9 10 import static org.junit.Assert.assertFalse; 11 import static org.junit.Assert.assertTrue; 12 import static org.mockito.internal.matchers.Equality.areEqual; 13 14 public class EqualityTest extends TestBase { 15 16 @Test shouldKnowIfObjectsAreEqual()17 public void shouldKnowIfObjectsAreEqual() throws Exception { 18 int[] arr = new int[] {1, 2}; 19 assertTrue(areEqual(arr, arr)); 20 assertTrue(areEqual(new int[] {1, 2}, new int[] {1, 2})); 21 assertTrue(areEqual(new Double[] {1.0}, new Double[] {1.0})); 22 assertTrue(areEqual(new String[0], new String[0])); 23 assertTrue(areEqual(new Object[10], new Object[10])); 24 assertTrue(areEqual(new int[] {1}, new Integer[] {1})); 25 assertTrue(areEqual(new Object[] {"1"}, new String[] {"1"})); 26 Object badequals=new BadEquals(); 27 assertTrue(areEqual(badequals,badequals)); 28 29 assertFalse(areEqual(new Object[9], new Object[10])); 30 assertFalse(areEqual(new int[] {1, 2}, new int[] {1})); 31 assertFalse(areEqual(new int[] {1}, new double[] {1.0})); 32 } 33 34 private final class BadEquals { 35 @Override equals(Object oth)36 public boolean equals(Object oth) { 37 throw new RuntimeException(); 38 } 39 } 40 } 41