Minor refactorings and code style changes. 1) Removed several use of raw types 2) Removed unnecessary throws clauses 3) Used lambda expressions wherever applicable 4) Used apt assertion methods for readability 5) Use of try with resources wherever applicable 6) Corrected incorrect order of assertXXX arguments

This commit is contained in:
Narendra Pathai
2018-10-20 17:50:52 +05:30
parent 2f569d670a
commit 543eb9a4be
73 changed files with 207 additions and 298 deletions

View File

@@ -70,18 +70,18 @@ public class App {
List<Creature> walkingCreatures =
creatures.stream().filter(new MovementSelector(Movement.WALKING))
.collect(Collectors.toList());
walkingCreatures.stream().forEach(c -> LOGGER.info(c.toString()));
walkingCreatures.forEach(c -> LOGGER.info(c.toString()));
// find all dark creatures
LOGGER.info("Find all dark creatures");
List<Creature> darkCreatures =
creatures.stream().filter(new ColorSelector(Color.DARK)).collect(Collectors.toList());
darkCreatures.stream().forEach(c -> LOGGER.info(c.toString()));
darkCreatures.forEach(c -> LOGGER.info(c.toString()));
// find all red and flying creatures
LOGGER.info("Find all red and flying creatures");
List<Creature> redAndFlyingCreatures =
creatures.stream()
.filter(new ColorSelector(Color.RED).and(new MovementSelector(Movement.FLYING)))
.collect(Collectors.toList());
redAndFlyingCreatures.stream().forEach(c -> LOGGER.info(c.toString()));
redAndFlyingCreatures.forEach(c -> LOGGER.info(c.toString()));
}
}

View File

@@ -57,33 +57,33 @@ public class CreatureTest {
@ParameterizedTest
@MethodSource("dataProvider")
public void testGetName(Creature testedCreature, String name) throws Exception {
public void testGetName(Creature testedCreature, String name) {
assertEquals(name, testedCreature.getName());
}
@ParameterizedTest
@MethodSource("dataProvider")
public void testGetSize(Creature testedCreature, String name, Size size) throws Exception {
public void testGetSize(Creature testedCreature, String name, Size size) {
assertEquals(size, testedCreature.getSize());
}
@ParameterizedTest
@MethodSource("dataProvider")
public void testGetMovement(Creature testedCreature, String name, Size size, Movement movement) throws Exception {
public void testGetMovement(Creature testedCreature, String name, Size size, Movement movement) {
assertEquals(movement, testedCreature.getMovement());
}
@ParameterizedTest
@MethodSource("dataProvider")
public void testGetColor(Creature testedCreature, String name, Size size, Movement movement,
Color color) throws Exception {
Color color) {
assertEquals(color, testedCreature.getColor());
}
@ParameterizedTest
@MethodSource("dataProvider")
public void testToString(Creature testedCreature, String name, Size size, Movement movement,
Color color) throws Exception {
Color color) {
final String toString = testedCreature.toString();
assertNotNull(toString);
assertEquals(