From 82995423dca0726f46e29700032b64fb354fdbf9 Mon Sep 17 00:00:00 2001 From: eugenp Date: Wed, 25 Dec 2013 14:37:06 +0200 Subject: [PATCH] eclipse and cleanup work --- core-java-8/pom.xml | 4 ++-- ...orUnitTest.java => Java8SortUnitTest.java} | 10 ++++------ .../java/org/baeldung/java8/entity/Human.java | 19 +++++++++++++++++-- 3 files changed, 23 insertions(+), 10 deletions(-) rename core-java-8/src/test/java/org/baeldung/java8/{Java8ComparatorUnitTest.java => Java8SortUnitTest.java} (61%) diff --git a/core-java-8/pom.xml b/core-java-8/pom.xml index cd690f1e71..aacc12ec67 100644 --- a/core-java-8/pom.xml +++ b/core-java-8/pom.xml @@ -86,8 +86,8 @@ maven-compiler-plugin ${maven-compiler-plugin.version} - 1.7 - 1.7 + 1.8 + 1.8 diff --git a/core-java-8/src/test/java/org/baeldung/java8/Java8ComparatorUnitTest.java b/core-java-8/src/test/java/org/baeldung/java8/Java8SortUnitTest.java similarity index 61% rename from core-java-8/src/test/java/org/baeldung/java8/Java8ComparatorUnitTest.java rename to core-java-8/src/test/java/org/baeldung/java8/Java8SortUnitTest.java index 8a2a2cd3d8..cc068e68ee 100644 --- a/core-java-8/src/test/java/org/baeldung/java8/Java8ComparatorUnitTest.java +++ b/core-java-8/src/test/java/org/baeldung/java8/Java8SortUnitTest.java @@ -1,7 +1,5 @@ package org.baeldung.java8; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; - import java.util.Collections; import java.util.List; @@ -10,15 +8,15 @@ import org.junit.Test; import com.google.common.collect.Lists; -public class Java8ComparatorUnitTest { +public class Java8SortUnitTest { // tests - @Test - public final void when_thenCorrect() { - final List humans = Lists.newArrayList(new Human(randomAlphabetic(5)), new Human(randomAlphabetic(5))); + public final void whenSortingEntitiesByName_thenCorrectlySorted() { + final List humans = Lists.newArrayList(new Human("Sarah", 10), new Human("Jack", 12)); Collections.sort(humans, (final Human h1, final Human h2) -> h1.getName().compareTo(h2.getName())); - System.out.println(humans); + // Assert.assertThat(actual, matcher); } } diff --git a/core-java-8/src/test/java/org/baeldung/java8/entity/Human.java b/core-java-8/src/test/java/org/baeldung/java8/entity/Human.java index e5d96262bf..09688412d0 100644 --- a/core-java-8/src/test/java/org/baeldung/java8/entity/Human.java +++ b/core-java-8/src/test/java/org/baeldung/java8/entity/Human.java @@ -2,15 +2,17 @@ package org.baeldung.java8.entity; public class Human { private String name; + private int age; public Human() { super(); } - public Human(final String name) { + public Human(final String name, final int age) { super(); this.name = name; + this.age = age; } // API @@ -23,11 +25,21 @@ public class Human { this.name = name; } + public int getAge() { + return age; + } + + public void setAge(final int age) { + this.age = age; + } + // + @Override public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + age; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @@ -44,6 +56,9 @@ public class Human { return false; } final Human other = (Human) obj; + if (age != other.age) { + return false; + } if (name == null) { if (other.name != null) { return false; @@ -57,7 +72,7 @@ public class Human { @Override public String toString() { final StringBuilder builder = new StringBuilder(); - builder.append("Human [name=").append(name).append("]"); + builder.append("Human [name=").append(name).append(", age=").append(age).append("]"); return builder.toString(); }