correct failing tests in com.baeldung.repository.FruitRepositoryIntegrationTest

This commit is contained in:
fanatixan
2019-09-08 15:09:54 +02:00
parent ff5da47f88
commit 1617026881
3 changed files with 8 additions and 8 deletions

View File

@@ -23,5 +23,5 @@ public interface FruitRepository extends JpaRepository<Fruit, Long> {
@Modifying
@Query("delete from Fruit f where f.name=:name or f.color=:color")
List<Fruit> deleteFruits(@Param("name") String name, @Param("color") String color);
int deleteFruits(@Param("name") String name, @Param("color") String color);
}

View File

@@ -1,7 +1,6 @@
package com.baeldung.repository;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.List;
@@ -69,9 +68,8 @@ class FruitRepositoryIntegrationTest {
@Sql(scripts = { "/test-fruit-data.sql" })
public void givenFruits_WhenDeletedByColorOrName_ThenDeletedFruitsShouldReturn() {
List<Fruit> fruits = fruitRepository.deleteFruits("apple", "green");
int deletedCount = fruitRepository.deleteFruits("apple", "green");
assertEquals("number of fruits are not matching", 3, fruits.size());
fruits.forEach(fruit -> assertTrue("Its not a green fruit or apple", ("green".equals(fruit.getColor())) || "apple".equals(fruit.getColor())));
assertEquals("number of fruits are not matching", 3, deletedCount);
}
}

View File

@@ -1,4 +1,6 @@
insert into fruit(id,name,color) values (1,'apple','red');
insert into fruit(id,name,color) values (2,'custard apple','green');
insert into fruit(id,name,color) values (3,'mango','yellow');
truncate table fruit;
insert into fruit(id,name,color) values (1,'apple','red');
insert into fruit(id,name,color) values (2,'custard apple','green');
insert into fruit(id,name,color) values (3,'mango','yellow');
insert into fruit(id,name,color) values (4,'guava','green');