Reduce the number of conditional operators for equals(). Improve
testEquals() to better cover this method.
This patch also:
* immediately returns expression instead of assigning it to the
temporary variable "str",
* adds the "@Override" annotation above equals() method signature.
Issue-ID: PORTAL-595
Change-Id: I15f600acce873eb3f22cc405d06a50890c7e87c3
Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
}
public Long getAppRoleId() {
}
public Long getAppRoleId() {
- return (role.getAppRoleId() == null) ? null : role.getAppRoleId();
+ return this.role.getAppRoleId();
}
@Override
public String toString() {
}
@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() {
}
public Long getUserId() {
this.priority = priority;
}
this.priority = priority;
}
public boolean equals(Object other) {
if ((this == other))
return true;
public boolean equals(Object other) {
if ((this == other))
return true;
return false;
EPUserApp castOther = (EPUserApp) other;
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() {
}
public int hashCode() {
return c1.compareTo(c2);
}
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());
+ }
@Test
public void testEquals(){
@Test
public void testEquals(){
EPRole epRole = new EPRole();
epRole.setId((long) 12345);
epRole.setName("test");
EPRole epRole = new EPRole();
epRole.setId((long) 12345);
epRole.setName("test");
epRole.setPriority(1);
epRole.setAppId((long)1);
epRole.setAppRoleId((long)1);
epRole.setPriority(1);
epRole.setAppId((long)1);
epRole.setAppRoleId((long)1);
EPUserApp user1 = mockEPUserApp();
user1.setApp(mockEPApp());
user1.setRole(epRole);
EPUserApp user1 = mockEPUserApp();
user1.setApp(mockEPApp());
user1.setRole(epRole);
EPUserApp user2 = mockEPUserApp();
user2.setApp(mockEPApp());
user2.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));
assertTrue(user1.equals(user2));
private EPApp mockEPApp() {
EPApp epApp = new EPApp();
epApp.setId((long) 12345);
private EPApp mockEPApp() {
EPApp epApp = new EPApp();
epApp.setId((long) 12345);