summaryrefslogtreecommitdiffstats
path: root/common/src/main
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2018-03-28 10:12:15 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2018-03-28 12:08:08 -0400
commit1f8f50733aaaa103cdb7e34099179cba436f754c (patch)
treee4c771841728c279b90cc1b0213f79c4c26bcb4b /common/src/main
parent4e651eb259dac4188e1568ac65e69d68a91e6296 (diff)
improved coverage for catalog db beans
Change-Id: Ibf1fd21dc81f0a3e16447b05dfce1761efa69237 Issue-ID: SO-541 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'common/src/main')
-rw-r--r--common/src/main/java/org/openecomp/mso/openpojo/rules/EqualsAndHashCodeTester.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/common/src/main/java/org/openecomp/mso/openpojo/rules/EqualsAndHashCodeTester.java b/common/src/main/java/org/openecomp/mso/openpojo/rules/EqualsAndHashCodeTester.java
index f4192e6cc8..9540409e16 100644
--- a/common/src/main/java/org/openecomp/mso/openpojo/rules/EqualsAndHashCodeTester.java
+++ b/common/src/main/java/org/openecomp/mso/openpojo/rules/EqualsAndHashCodeTester.java
@@ -23,6 +23,7 @@ package org.openecomp.mso.openpojo.rules;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.anything;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -44,6 +45,7 @@ public class EqualsAndHashCodeTester implements Tester {
private final Matcher m;
+ private boolean onlyDeclaredMethods = false;
public EqualsAndHashCodeTester() {
m = anything();
}
@@ -51,12 +53,33 @@ public class EqualsAndHashCodeTester implements Tester {
public EqualsAndHashCodeTester(Matcher m) {
this.m = m;
}
+
+ public EqualsAndHashCodeTester onlyDeclaredMethods() {
+ this.onlyDeclaredMethods = true;
+ return this;
+ }
@Override
public void run(PojoClass pojoClass) {
Class<?> clazz = pojoClass.getClazz();
if (anyOf(m).matches(clazz)) {
final Object classInstanceOne = ValidationHelper.getBasicInstance(pojoClass);
final Object classInstanceTwo = ValidationHelper.getBasicInstance(pojoClass);
+ if (onlyDeclaredMethods) {
+ Method[] methods = classInstanceOne.getClass().getDeclaredMethods();
+ boolean hasEquals = false;
+ boolean hasHashcode = false;
+ for (Method method : methods) {
+ if (method.getName().equals("equals")) {
+ hasEquals = true;
+ } else if (method.getName().equals("hashCode")) {
+ hasHashcode = true;
+ }
+ }
+
+ if (!(hasEquals && hasHashcode)) {
+ return;
+ }
+ }
Set<PojoField> identityFields = hasIdOrBusinessKey(pojoClass);
List<PojoField> otherFields = new ArrayList<>(pojoClass.getPojoFields());
otherFields.removeAll(identityFields);