Skip to content
Snippets Groups Projects
Commit 9257a7c6 authored by Birk Øvstetun Narvhus's avatar Birk Øvstetun Narvhus
Browse files

added tests for equals and hash code in respons dtos

parent bca73d32
No related branches found
No related tags found
No related merge requests found
package ntnu.idatt2016.v233.SmartMat.dto.response;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class AllergyResponseTest {
@Test
void testEquals() {
AllergyResponse allergyResponse = AllergyResponse.builder()
.name("test")
.description("test")
.build();
AllergyResponse allergyResponse1 = AllergyResponse.builder()
.name("test")
.description("test")
.build();
assertEquals(allergyResponse, allergyResponse1);
allergyResponse1.setName("test2");
assertNotEquals(allergyResponse, allergyResponse1);
allergyResponse1.setName("test");
allergyResponse1.setDescription("test2");
assertNotEquals(allergyResponse, allergyResponse1);
assertEquals(allergyResponse, allergyResponse);
}
@Test
void testHashCode() {
AllergyResponse allergyResponse = AllergyResponse.builder()
.name("test")
.description("test")
.build();
AllergyResponse allergyResponse1 = AllergyResponse.builder()
.name("test")
.description("test")
.build();
assertEquals(allergyResponse.hashCode(), allergyResponse1.hashCode());
allergyResponse1.setName("test2");
assertNotEquals(allergyResponse.hashCode(), allergyResponse1.hashCode());
}
}
\ No newline at end of file
package ntnu.idatt2016.v233.SmartMat.dto.response;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class RecipeDetailsTest {
@Test
void testEquals() {
RecipeDetails recipeDetails = RecipeDetails.builder()
.recipeDescription("test")
.build();
RecipeDetails recipeDetails1 = RecipeDetails.builder()
.recipeDescription("test")
.build();
assertEquals(recipeDetails, recipeDetails1);
recipeDetails1.setRecipeDescription("test2");
assertNotEquals(recipeDetails, recipeDetails1);
recipeDetails1.setRecipeDescription("test");
recipeDetails1.setRecipeId(123);
assertNotEquals(recipeDetails, recipeDetails1);
assertEquals(recipeDetails, recipeDetails);
}
@Test
void testHashCode() {
RecipeDetails recipeDetails = RecipeDetails.builder()
.recipeDescription("test")
.build();
RecipeDetails recipeDetails1 = RecipeDetails.builder()
.recipeDescription("test")
.build();
assertEquals(recipeDetails.hashCode(), recipeDetails1.hashCode());
recipeDetails1.setRecipeDescription("test2");
assertNotEquals(recipeDetails.hashCode(), recipeDetails1.hashCode());
}
}
\ No newline at end of file
package ntnu.idatt2016.v233.SmartMat.dto.response;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class RecipeWithMatchCountTest {
@Test
void testEquals() {
RecipeDetails recipeDetails = RecipeDetails.builder()
.recipeDescription("test")
.build();
RecipeDetails recipeDetails1 = RecipeDetails.builder()
.recipeDescription("test")
.build();
RecipeWithMatchCount recipeWithMatchCount = RecipeWithMatchCount.builder()
.recipeDetails(recipeDetails)
.build();
RecipeWithMatchCount recipeWithMatchCount1 = RecipeWithMatchCount.builder()
.recipeDetails(recipeDetails1)
.build();
assertEquals(recipeWithMatchCount, recipeWithMatchCount1);
recipeWithMatchCount1.setMatchCount(123);
assertNotEquals(recipeWithMatchCount, recipeWithMatchCount1);
recipeWithMatchCount1.setMatchCount(0);
assertEquals(recipeWithMatchCount, recipeWithMatchCount1);
}
@Test
void testHashCode() {
RecipeDetails recipeDetails = RecipeDetails.builder()
.recipeDescription("test")
.build();
RecipeDetails recipeDetails1 = RecipeDetails.builder()
.recipeDescription("test")
.build();
RecipeWithMatchCount recipeWithMatchCount = RecipeWithMatchCount.builder()
.recipeDetails(recipeDetails)
.build();
RecipeWithMatchCount recipeWithMatchCount1 = RecipeWithMatchCount.builder()
.recipeDetails(recipeDetails1)
.build();
assertEquals(recipeWithMatchCount.hashCode(), recipeWithMatchCount1.hashCode());
recipeWithMatchCount1.setMatchCount(123);
assertNotEquals(recipeWithMatchCount.hashCode(), recipeWithMatchCount1.hashCode());
}
}
\ No newline at end of file
package ntnu.idatt2016.v233.SmartMat.dto.response;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class WeeklyMenuResponseTest {
@Test
void testEquals() {
WeeklyMenuResponse weeklyMenuResponse = WeeklyMenuResponse.builder()
.recipeDescription("test")
.matchingProducts(123L)
.build();
WeeklyMenuResponse weeklyMenuResponse1 = WeeklyMenuResponse.builder()
.recipeDescription("test")
.matchingProducts(123L)
.build();
assertEquals(weeklyMenuResponse, weeklyMenuResponse1);
weeklyMenuResponse1.setRecipeDescription("test2");
assertNotEquals(weeklyMenuResponse, weeklyMenuResponse1);
weeklyMenuResponse1.setRecipeDescription("test");
weeklyMenuResponse1.setMatchingProducts(321L);
assertNotEquals(weeklyMenuResponse, weeklyMenuResponse1);
weeklyMenuResponse1.setMatchingProducts(123L);
weeklyMenuResponse1.setRecipeId(123);
assertNotEquals(weeklyMenuResponse, weeklyMenuResponse1);
assertEquals(weeklyMenuResponse, weeklyMenuResponse);
}
@Test
void testHashCode() {
WeeklyMenuResponse weeklyMenuResponse = WeeklyMenuResponse.builder()
.recipeDescription("test")
.matchingProducts(123L)
.build();
WeeklyMenuResponse weeklyMenuResponse1 = WeeklyMenuResponse.builder()
.recipeDescription("test")
.matchingProducts(123L)
.build();
assertEquals(weeklyMenuResponse.hashCode(), weeklyMenuResponse1.hashCode());
weeklyMenuResponse1.setRecipeDescription("test2");
assertNotEquals(weeklyMenuResponse.hashCode(), weeklyMenuResponse1.hashCode());
weeklyMenuResponse1.setRecipeDescription("test");
weeklyMenuResponse1.setMatchingProducts(321L);
assertNotEquals(weeklyMenuResponse.hashCode(), weeklyMenuResponse1.hashCode());
weeklyMenuResponse1.setMatchingProducts(123L);
weeklyMenuResponse1.setRecipeId(123);
assertNotEquals(weeklyMenuResponse.hashCode(), weeklyMenuResponse1.hashCode());
assertEquals(weeklyMenuResponse.hashCode(), weeklyMenuResponse.hashCode());
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment