2016-01-28 22:39:50 +09:00
|
|
|
package com.iluwatar.value.object;
|
|
|
|
|
2016-01-29 00:53:27 +09:00
|
|
|
import static org.hamcrest.CoreMatchers.is;
|
|
|
|
import static org.hamcrest.CoreMatchers.not;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertThat;
|
|
|
|
|
2016-01-28 22:39:50 +09:00
|
|
|
import com.google.common.testing.EqualsTester;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit test for HeroStat.
|
|
|
|
*/
|
|
|
|
public class HeroStatTest {
|
|
|
|
|
|
|
|
/**
|
2016-02-03 23:38:13 +09:00
|
|
|
* Tester for equals() and hashCode() methods of a class. Using guava's EqualsTester.
|
2016-01-29 00:53:27 +09:00
|
|
|
*
|
2016-02-03 22:49:59 +09:00
|
|
|
* @see http://static.javadoc.io/com.google.guava/guava-testlib/19.0/com/google/common/testing/
|
|
|
|
* EqualsTester.html
|
2016-01-28 22:39:50 +09:00
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testEquals() {
|
|
|
|
HeroStat heroStatA = HeroStat.valueOf(3, 9, 2);
|
|
|
|
HeroStat heroStatB = HeroStat.valueOf(3, 9, 2);
|
|
|
|
new EqualsTester().addEqualityGroup(heroStatA, heroStatB).testEquals();
|
|
|
|
}
|
|
|
|
|
2016-01-29 00:53:27 +09:00
|
|
|
/**
|
|
|
|
* The toString() for two equal values must be the same. For two non-equal values it must be
|
|
|
|
* different.
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testToString() {
|
|
|
|
HeroStat heroStatA = HeroStat.valueOf(3, 9, 2);
|
|
|
|
HeroStat heroStatB = HeroStat.valueOf(3, 9, 2);
|
|
|
|
HeroStat heroStatC = HeroStat.valueOf(3, 9, 8);
|
|
|
|
|
|
|
|
assertThat(heroStatA.toString(), is(heroStatB.toString()));
|
|
|
|
assertThat(heroStatA.toString(), is(not(heroStatC.toString())));
|
|
|
|
}
|
|
|
|
|
2016-01-28 22:39:50 +09:00
|
|
|
}
|