made the tests more readable...
This commit is contained in:
parent
4d17f10323
commit
9222999505
1 changed files with 39 additions and 14 deletions
|
|
@ -67,7 +67,9 @@ public class RecipeControllerTest {
|
||||||
.mapToObj(x -> new Recipe(
|
.mapToObj(x -> new Recipe(
|
||||||
null,
|
null,
|
||||||
"Recipe " + x,
|
"Recipe " + x,
|
||||||
"en", List.of(), List.of()))
|
"en",
|
||||||
|
List.of(),
|
||||||
|
List.of()))
|
||||||
.toList();
|
.toList();
|
||||||
controller = new RecipeController(
|
controller = new RecipeController(
|
||||||
recipeService,
|
recipeService,
|
||||||
|
|
@ -80,8 +82,11 @@ public class RecipeControllerTest {
|
||||||
if (tags.contains("test-from-init-data")) {
|
if (tags.contains("test-from-init-data")) {
|
||||||
ids = LongStream
|
ids = LongStream
|
||||||
.range(0, NUM_RECIPES)
|
.range(0, NUM_RECIPES)
|
||||||
.map(idx -> recipeRepository.save(recipes.get((int) idx)).getId())
|
.map(idx -> recipeRepository
|
||||||
.boxed().toList();
|
.save(recipes.get((int) idx))
|
||||||
|
.getId())
|
||||||
|
.boxed()
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some tests need to know the stored IDs of objects
|
// Some tests need to know the stored IDs of objects
|
||||||
|
|
@ -117,7 +122,9 @@ public class RecipeControllerTest {
|
||||||
controller.getRecipes(
|
controller.getRecipes(
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
Optional.of(List.of("en", "nl"))).getBody().size());;
|
Optional.of(List.of("en", "nl")))
|
||||||
|
.getBody()
|
||||||
|
.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -129,7 +136,9 @@ public class RecipeControllerTest {
|
||||||
controller.getRecipes(
|
controller.getRecipes(
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
Optional.of(LIMIT),
|
Optional.of(LIMIT),
|
||||||
Optional.of(List.of("en"))).getBody().size());
|
Optional.of(List.of("en")))
|
||||||
|
.getBody()
|
||||||
|
.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -140,7 +149,9 @@ public class RecipeControllerTest {
|
||||||
controller.getRecipes(
|
controller.getRecipes(
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
Optional.of(List.of("en", "nl"))).getBody().size());
|
Optional.of(List.of("en", "nl")))
|
||||||
|
.getBody()
|
||||||
|
.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -151,7 +162,9 @@ public class RecipeControllerTest {
|
||||||
controller.getRecipes(
|
controller.getRecipes(
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
Optional.of(List.of("nl"))).getBody().size());
|
Optional.of(List.of("nl")))
|
||||||
|
.getBody()
|
||||||
|
.size());
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
@Tag("test-from-init-data")
|
@Tag("test-from-init-data")
|
||||||
|
|
@ -161,7 +174,9 @@ public class RecipeControllerTest {
|
||||||
controller.getRecipes(
|
controller.getRecipes(
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
Optional.of(LIMIT),
|
Optional.of(LIMIT),
|
||||||
Optional.of(List.of("en", "nl"))).getBody().size());
|
Optional.of(List.of("en", "nl")))
|
||||||
|
.getBody()
|
||||||
|
.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -172,7 +187,8 @@ public class RecipeControllerTest {
|
||||||
// The third item in the input list is the same as the third item retrieved from the database
|
// The third item in the input list is the same as the third item retrieved from the database
|
||||||
assertEquals(
|
assertEquals(
|
||||||
recipes.get(CHECK_INDEX),
|
recipes.get(CHECK_INDEX),
|
||||||
controller.getRecipe(recipeIds.get(CHECK_INDEX)).getBody());
|
controller.getRecipe(recipeIds.get(CHECK_INDEX))
|
||||||
|
.getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -181,7 +197,8 @@ public class RecipeControllerTest {
|
||||||
// There does not exist a recipe with ID=3 since there are no items in the repository.
|
// There does not exist a recipe with ID=3 since there are no items in the repository.
|
||||||
assertEquals(
|
assertEquals(
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
controller.getRecipe((long) CHECK_INDEX).getStatusCode());
|
controller.getRecipe((long) CHECK_INDEX)
|
||||||
|
.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -192,7 +209,8 @@ public class RecipeControllerTest {
|
||||||
|
|
||||||
// The object has been successfully deleted
|
// The object has been successfully deleted
|
||||||
assertEquals(HttpStatus.OK,
|
assertEquals(HttpStatus.OK,
|
||||||
controller.deleteRecipe(recipeIds.get(DELETE_INDEX)).getStatusCode());
|
controller.deleteRecipe(recipeIds.get(DELETE_INDEX))
|
||||||
|
.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -211,7 +229,8 @@ public class RecipeControllerTest {
|
||||||
public void deleteOneRecipeFail() {
|
public void deleteOneRecipeFail() {
|
||||||
final Long DELETE_INDEX = 5L;
|
final Long DELETE_INDEX = 5L;
|
||||||
assertEquals(HttpStatus.BAD_REQUEST,
|
assertEquals(HttpStatus.BAD_REQUEST,
|
||||||
controller.deleteRecipe(DELETE_INDEX).getStatusCode());
|
controller.deleteRecipe(DELETE_INDEX)
|
||||||
|
.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -219,10 +238,16 @@ public class RecipeControllerTest {
|
||||||
@Tag("need-ids")
|
@Tag("need-ids")
|
||||||
public void updateOneRecipeHasNewData() {
|
public void updateOneRecipeHasNewData() {
|
||||||
final int UPDATE_INDEX = 5;
|
final int UPDATE_INDEX = 5;
|
||||||
Recipe newRecipe = controller.getRecipe(recipeIds.get(UPDATE_INDEX)).getBody();
|
Recipe newRecipe = controller.getRecipe(recipeIds
|
||||||
|
.get(UPDATE_INDEX))
|
||||||
|
.getBody();
|
||||||
|
|
||||||
newRecipe.setName("New recipe");
|
newRecipe.setName("New recipe");
|
||||||
controller.updateRecipe(newRecipe.getId(), newRecipe);
|
controller.updateRecipe(newRecipe.getId(), newRecipe);
|
||||||
|
|
||||||
assertEquals("New recipe",
|
assertEquals("New recipe",
|
||||||
recipeRepository.getReferenceById(recipeIds.get(UPDATE_INDEX)).getName());
|
recipeRepository.getReferenceById(recipeIds
|
||||||
|
.get(UPDATE_INDEX))
|
||||||
|
.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue