Skip to content

Commit 98c3f93

Browse files
committed
Review changes in Test Cases
1 parent 26fbbed commit 98c3f93

File tree

2 files changed

+63
-4
lines changed
  • collection-pipeline/src
    • main/java/com/iluwatar/collectionpipeline
    • test/java/com/iluwatar/collectionpipeline

2 files changed

+63
-4
lines changed

collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/Car.java

+46
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,52 @@ public Car(String make, String model, int yearOfMake, Category category) {
4545
this.category = category;
4646
}
4747

48+
@Override
49+
public int hashCode() {
50+
final int prime = 31;
51+
int result = 1;
52+
result = prime * result + ((category == null) ? 0 : category.hashCode());
53+
result = prime * result + ((make == null) ? 0 : make.hashCode());
54+
result = prime * result + ((model == null) ? 0 : model.hashCode());
55+
result = prime * result + year;
56+
return result;
57+
}
58+
59+
@Override
60+
public boolean equals(Object obj) {
61+
if (this == obj) {
62+
return true;
63+
}
64+
if (obj == null) {
65+
return false;
66+
}
67+
if (getClass() != obj.getClass()) {
68+
return false;
69+
}
70+
Car other = (Car) obj;
71+
if (category != other.category) {
72+
return false;
73+
}
74+
if (make == null) {
75+
if (other.make != null) {
76+
return false;
77+
}
78+
} else if (!make.equals(other.make)) {
79+
return false;
80+
}
81+
if (model == null) {
82+
if (other.model != null) {
83+
return false;
84+
}
85+
} else if (!model.equals(other.model)) {
86+
return false;
87+
}
88+
if (year != other.year) {
89+
return false;
90+
}
91+
return true;
92+
}
93+
4894
public String getMake() {
4995
return make;
5096
}

collection-pipeline/src/test/java/com/iluwatar/collectionpipeline/AppTest.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static org.junit.jupiter.api.Assertions.assertEquals;
2626

2727
import java.util.Arrays;
28+
import java.util.HashMap;
2829
import java.util.List;
2930
import java.util.Map;
3031

@@ -40,27 +41,39 @@ public class AppTest {
4041
@Test
4142
public void testGetModelsAfter2000UsingFor() {
4243
List<String> models = ImperativeProgramming.getModelsAfter2000(cars);
43-
assertEquals(models, Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"));
44+
assertEquals(Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"), models);
4445
}
4546

4647
@Test
4748
public void testGetModelsAfter2000UsingPipeline() {
4849
List<String> models = FunctionalProgramming.getModelsAfter2000(cars);
49-
assertEquals(models, Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"));
50+
assertEquals(Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"), models);
5051
}
5152

5253
@Test
5354
public void testGetGroupingOfCarsByCategory() {
55+
Map<Category, List<Car>> modelsExpected = new HashMap<>();
56+
modelsExpected.put(Category.CONVERTIBLE, Arrays.asList(new Car("Buick", "Cascada", 2016, Category.CONVERTIBLE),
57+
new Car("Chevrolet", "Geo Metro", 1992, Category.CONVERTIBLE)));
58+
modelsExpected.put(Category.SEDAN, Arrays.asList(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
59+
new Car("Ford", "Focus", 2012, Category.SEDAN)));
60+
modelsExpected.put(Category.JEEP, Arrays.asList(new Car("Jeep", "Wrangler", 2011, Category.JEEP),
61+
new Car("Jeep", "Comanche", 1990, Category.JEEP)));
5462
Map<Category, List<Car>> modelsFunctional = FunctionalProgramming.getGroupingOfCarsByCategory(cars);
5563
Map<Category, List<Car>> modelsImperative = ImperativeProgramming.getGroupingOfCarsByCategory(cars);
56-
assertEquals(modelsFunctional, modelsImperative);
64+
System.out.println("Category " + modelsFunctional);
65+
assertEquals(modelsExpected, modelsFunctional);
66+
assertEquals(modelsExpected, modelsImperative);
5767
}
5868

5969
@Test
6070
public void testGetSedanCarsOwnedSortedByDate() {
6171
Person john = new Person(cars);
72+
List<Car> modelsExpected = Arrays.asList(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
73+
new Car("Ford", "Focus", 2012, Category.SEDAN));
6274
List<Car> modelsFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
6375
List<Car> modelsImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
64-
assertEquals(modelsFunctional, modelsImperative);
76+
assertEquals(modelsExpected, modelsFunctional);
77+
assertEquals(modelsExpected, modelsImperative);
6578
}
6679
}

0 commit comments

Comments
 (0)