summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunder Tattavarada <statta@research.att.com>2019-06-17 15:51:58 +0000
committerGerrit Code Review <gerrit@onap.org>2019-06-17 15:51:58 +0000
commit8b67487fa29e61ad15ac961231ebb3b6621d39dc (patch)
tree74b6f223826067de948c07da641f65f5adbbe6c1
parent4027435c28e1433df2476b83a6e77ba4d1d865bd (diff)
parent788e99d836a75badf45dce96358d184aa9e549f2 (diff)
Merge "Sonar: Reduce cyclomatic complexity"
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserApp.java29
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppTest.java16
2 files changed, 31 insertions, 14 deletions
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserApp.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserApp.java
index 424a9152..d644c998 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserApp.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserApp.java
@@ -64,13 +64,12 @@ public class EPUserApp extends DomainVo implements java.io.Serializable, Compara
}
public Long getAppRoleId() {
- return (role.getAppRoleId() == null) ? null : role.getAppRoleId();
+ return this.role.getAppRoleId();
}
@Override
public String toString() {
- String str = "[u: "+getUserId()+"; a: "+getAppId()+", r: "+getRoleId()+"; appRoleId: "+getAppRoleId()+"]";
- return str;
+ return "[u: "+getUserId()+"; a: "+getAppId()+", r: "+getRoleId()+"; appRoleId: "+getAppRoleId()+"]";
}
public Long getUserId() {
@@ -105,6 +104,7 @@ public class EPUserApp extends DomainVo implements java.io.Serializable, Compara
this.priority = priority;
}
+ @Override
public boolean equals(Object other) {
if ((this == other))
return true;
@@ -114,10 +114,10 @@ public class EPUserApp extends DomainVo implements java.io.Serializable, Compara
return false;
EPUserApp castOther = (EPUserApp) other;
- return (this.getUserId().equals(castOther.getUserId()))
- && (this.getApp().getId().equals(castOther.getApp().getId()))
- && (this.getRole().getId().equals(castOther.getRole().getId()))
- && ((this.priority==null && castOther.getPriority()==null) || this.getPriority().equals(castOther.getPriority()));
+ return (otherUserIdIsSameAsThisUserId(castOther))
+ && (otherAppIdIsSameAsThis(castOther))
+ && (otherRoleIsSameAsThis(castOther))
+ && (otherPriorityIsSameAsThis(castOther));
}
public int hashCode() {
@@ -138,4 +138,19 @@ public class EPUserApp extends DomainVo implements java.io.Serializable, Compara
return c1.compareTo(c2);
}
+ private boolean otherPriorityIsSameAsThis(EPUserApp other){
+ return (this.priority==null && other.getPriority()==null) || this.getPriority().equals(other.getPriority());
+ }
+
+ private boolean otherRoleIsSameAsThis(EPUserApp other){
+ return this.getRole().getId().equals(other.getRole().getId());
+ }
+
+ private boolean otherAppIdIsSameAsThis(EPUserApp other){
+ return this.getApp().getId().equals(other.getApp().getId());
+ }
+
+ private boolean otherUserIdIsSameAsThisUserId(EPUserApp other){
+ return this.getUserId().equals(other.getUserId());
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppTest.java
index 2cc03a60..0923d033 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppTest.java
@@ -121,10 +121,9 @@ public class EPUserAppTest {
}
-
+
@Test
public void testEquals(){
-
EPRole epRole = new EPRole();
epRole.setId((long) 12345);
epRole.setName("test");
@@ -132,19 +131,22 @@ public class EPUserAppTest {
epRole.setPriority(1);
epRole.setAppId((long)1);
epRole.setAppRoleId((long)1);
-
+
EPUserApp user1 = mockEPUserApp();
user1.setApp(mockEPApp());
user1.setRole(epRole);
-
+
EPUserApp user2 = mockEPUserApp();
user2.setApp(mockEPApp());
user2.setRole(epRole);
-
+
+ EPUserApp nullUser = null;
+
+ assertTrue(user1.equals(user1));
+ assertFalse(user1.equals(nullUser));
+ assertFalse(user1.equals(Long.valueOf(1)));
assertTrue(user1.equals(user2));
-
}
-
private EPApp mockEPApp() {
EPApp epApp = new EPApp();
epApp.setId((long) 12345);