Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@ -2,18 +2,21 @@ package com.iluwatar.value.object;
|
||||
|
||||
/**
|
||||
* App Class.
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
/**
|
||||
* main method.
|
||||
* A Value Object must check equality with equals() not == <br>
|
||||
* This practice creates three HeroStats(Value object) and checks equality between those.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
HeroStat statA = HeroStat.valueOf(10, 5, 0);
|
||||
HeroStat statB = HeroStat.valueOf(5, 1, 8);
|
||||
HeroStat statB = HeroStat.valueOf(10, 5, 0);
|
||||
HeroStat statC = HeroStat.valueOf(5, 1, 8);
|
||||
|
||||
System.out.println(statA.toString());
|
||||
// When using Value Objects do not use ==, only compare using equals().
|
||||
System.out.println("is statA and statB equal : " + statA.equals(statB));
|
||||
|
||||
System.out.println("Is statA and statB equal : " + statA.equals(statB));
|
||||
System.out.println("Is statA and statC equal : " + statA.equals(statC));
|
||||
}
|
||||
}
|
||||
|
@ -48,15 +48,15 @@ public class HeroStat {
|
||||
|
||||
/*
|
||||
* Recommended to provide a static factory method capable of creating an instance from the formal
|
||||
* string representation declared like this. public static Juice parse(String string) {}
|
||||
* string representation declared like this. public static HeroStat parse(String string) {}
|
||||
*/
|
||||
|
||||
// toString, hashCode, equals
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HeroStat [strength=" + strength + ", intelligence=" + intelligence + ", luck=" + luck
|
||||
+ "]";
|
||||
return "HeroStat [strength=" + strength + ", intelligence=" + intelligence
|
||||
+ ", luck=" + luck + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -94,6 +94,6 @@ public class HeroStat {
|
||||
}
|
||||
|
||||
|
||||
// The clone() method should not be public
|
||||
// The clone() method should not be public. Just don't override it.
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.iluwatar.value.object;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Application test
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
}
|
@ -15,9 +15,10 @@ import org.junit.Test;
|
||||
public class HeroStatTest {
|
||||
|
||||
/**
|
||||
* Tester for equals() and hashCode() methods of a class.
|
||||
* Tester for equals() and hashCode() methods of a class. Using guava's EqualsTester
|
||||
*
|
||||
* @see http://www.javadoc.io/doc/com.google.guava/guava-testlib/19.0
|
||||
* @see http://static.javadoc.io/com.google.guava/guava-testlib/19.0/com/google/common/testing/
|
||||
* EqualsTester.html
|
||||
*/
|
||||
@Test
|
||||
public void testEquals() {
|
||||
|
Reference in New Issue
Block a user