From 54aad7deb7a02ecca4bc7ed4d7913ccd59eb3bf9 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Wed, 6 Mar 2019 14:25:02 +0200 Subject: Fix cyclic CategoryParameterOption::hashCode Issue-ID: VID-430 Change-Id: Ib49b71726fe508f1ec9bfe8c60836af1c5ca786b Signed-off-by: Ittay Stern --- .../org/onap/vid/model/CategoryParameterTest.java | 186 ++++----------------- 1 file changed, 32 insertions(+), 154 deletions(-) (limited to 'vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterTest.java') diff --git a/vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterTest.java b/vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterTest.java index dc18c3065..c515a34d4 100644 --- a/vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterTest.java @@ -20,186 +20,64 @@ package org.onap.vid.model; -import java.io.Serializable; -import java.util.Date; +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding; +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanHashCodeExcluding; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.onap.vid.testUtils.TestUtils.allPropertiesOf; + +import com.google.common.collect.ImmutableSet; import java.util.Set; - +import org.apache.commons.lang3.ArrayUtils; import org.junit.Test; +import org.onap.portalsdk.core.domain.support.DomainVo; public class CategoryParameterTest { - private CategoryParameter createTestSubject() { - return new CategoryParameter(); - } - - @Test - public void testGetFamily() throws Exception { - CategoryParameter testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getFamily(); - } - - @Test - public void testSetFamily() throws Exception { - CategoryParameter testSubject; - String family = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setFamily(family); - } - - @Test - public void testGetId() throws Exception { - CategoryParameter testSubject; - Long result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getId(); - } - - @Test - public void testGetCreated() throws Exception { - CategoryParameter testSubject; - Date result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getCreated(); - } - - @Test - public void testGetModified() throws Exception { - CategoryParameter testSubject; - Date result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getModified(); - } - - @Test - public void testGetCreatedId() throws Exception { - CategoryParameter testSubject; - Long result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getCreatedId(); - } - - @Test - public void testGetModifiedId() throws Exception { - CategoryParameter testSubject; - Long result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getModifiedId(); - } - - @Test - public void testGetName() throws Exception { - CategoryParameter testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getName(); - } - @Test - public void testSetName() throws Exception { - CategoryParameter testSubject; - String name = ""; + final private String[] excludedProperties = allPropertiesOf(DomainVo.class); - // default test - testSubject = createTestSubject(); - testSubject.setName(name); + private ImmutableSet optionsWithRefTo(CategoryParameter categoryParameter) { + return ImmutableSet.of( + new CategoryParameterOption("appId1", "name1", categoryParameter), + new CategoryParameterOption("appId2", "name2", categoryParameter) + ); } @Test - public void testGetAuditUserId() throws Exception { - CategoryParameter testSubject; - Serializable result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getAuditUserId(); + public void shouldHaveValidGettersAndSetters() { + assertThat(CategoryParameter.class, hasValidGettersAndSettersExcluding("options")); } @Test - public void testGetRowNum() throws Exception { - CategoryParameter testSubject; - Long result; + public void testSetAndGetOptions() { + CategoryParameter testSubject = new CategoryParameter(); - // default test - testSubject = createTestSubject(); - result = testSubject.getRowNum(); - } - - @Test - public void testGetAuditTrail() throws Exception { - CategoryParameter testSubject; - Set result; + Set options = optionsWithRefTo(testSubject); - // default test - testSubject = createTestSubject(); - result = testSubject.getAuditTrail(); + testSubject.setOptions(options); + assertThat(testSubject.getOptions(), containsInAnyOrder(optionsWithRefTo(testSubject).toArray())); } @Test - public void testGetOptions() throws Exception { - CategoryParameter testSubject; - Set result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getOptions(); + public void shouldHaveValidBeanHashCodeWithCycleReference() { + assertThat(CategoryParameter.class, + hasValidBeanHashCodeExcluding(ArrayUtils.addAll(new String[]{"options"}, excludedProperties))); } @Test - public void testSetOptions() throws Exception { - CategoryParameter testSubject; - Set options = null; - - // default test - testSubject = createTestSubject(); + public void hashCodeShouldNotExplodeWhenCycleReference() { + CategoryParameter testSubject = new CategoryParameter(); + Set options = optionsWithRefTo(testSubject); testSubject.setOptions(options); - } - @Test - public void testAddOption() throws Exception { - CategoryParameter testSubject; - CategoryParameterOption option = null; - boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.addOption(option); + testSubject.hashCode(); // don't stackOverflow } @Test - public void testIsIdSupported() throws Exception { - CategoryParameter testSubject; - boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.isIdSupported(); + public void shouldHaveValidBeanEquals() { + assertThat(CategoryParameter.class, hasValidBeanEqualsExcluding(excludedProperties)); } - @Test - public void testSetIdSupported() throws Exception { - CategoryParameter testSubject; - boolean idSupported = false; - - // default test - testSubject = createTestSubject(); - testSubject.setIdSupported(idSupported); - } } -- cgit 1.2.3-korg