Skip to content

Commit a4d2bc2

Browse files
committed
add tests for equals and hashcode methods
1 parent 35a5eda commit a4d2bc2

31 files changed

Lines changed: 367 additions & 85 deletions

src/main/java/com/gooddata/connector/CoupaInstance.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,23 @@ public String getApiKey() {
5858
}
5959

6060
@Override
61-
public boolean equals(Object o) {
62-
if (this == o)
63-
return true;
64-
if (!(o instanceof CoupaInstance))
65-
return false;
66-
CoupaInstance that = (CoupaInstance) o;
67-
return Objects.equals(name, that.name) &&
68-
Objects.equals(apiUrl, that.apiUrl) &&
69-
Objects.equals(apiKey, that.apiKey);
61+
public boolean equals(final Object o) {
62+
if (this == o) return true;
63+
if (o == null || getClass() != o.getClass()) return false;
64+
65+
final CoupaInstance that = (CoupaInstance) o;
66+
67+
if (name != null ? !name.equals(that.name) : that.name != null) return false;
68+
if (apiUrl != null ? !apiUrl.equals(that.apiUrl) : that.apiUrl != null) return false;
69+
return apiKey != null ? apiKey.equals(that.apiKey) : that.apiKey == null;
7070
}
7171

7272
@Override
7373
public int hashCode() {
74-
return Objects.hash(name, apiUrl, apiKey);
74+
int result = name != null ? name.hashCode() : 0;
75+
result = 31 * result + (apiUrl != null ? apiUrl.hashCode() : 0);
76+
result = 31 * result + (apiKey != null ? apiKey.hashCode() : 0);
77+
return result;
7578
}
7679

7780
@Override

src/main/java/com/gooddata/md/Attachment.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public boolean equals(Object o) {
4242
Attachment that = (Attachment) o;
4343

4444
return !(uri != null ? !uri.equals(that.uri) : that.uri != null);
45-
4645
}
4746

4847
@Override

src/main/java/com/gooddata/md/AttributeElement.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,14 @@ public String getTitle() {
3636
}
3737

3838
@Override
39-
public boolean equals(Object o) {
40-
if (this == o)
41-
return true;
42-
if (!(o instanceof AttributeElement))
43-
return false;
39+
public boolean equals(final Object o) {
40+
if (this == o) return true;
41+
if (o == null || getClass() != o.getClass()) return false;
4442

45-
AttributeElement that = (AttributeElement) o;
46-
47-
if (uri != null ? !uri.equals(that.uri) : that.uri != null)
48-
return false;
49-
return !(title != null ? !title.equals(that.title) : that.title != null);
43+
final AttributeElement that = (AttributeElement) o;
5044

45+
if (uri != null ? !uri.equals(that.uri) : that.uri != null) return false;
46+
return title != null ? title.equals(that.title) : that.title == null;
5147
}
5248

5349
@Override

src/main/java/com/gooddata/md/DashboardAttachment.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,29 @@ protected DashboardAttachment(
4141
public String getExecutionContext() { return executionContext; }
4242

4343
@Override
44-
public boolean equals(Object o) {
45-
if (!super.equals(o)) return false;
44+
public boolean equals(final Object o) {
4645
if (this == o) return true;
4746
if (o == null || getClass() != o.getClass()) return false;
47+
if (!super.equals(o)) return false;
4848

49-
DashboardAttachment that = (DashboardAttachment) o;
49+
final DashboardAttachment that = (DashboardAttachment) o;
5050

51+
if (getUri() != null ? !getUri().equals(that.getUri()) : that.getUri() != null) return false;
5152
if (allTabs != null ? !allTabs.equals(that.allTabs) : that.allTabs != null) return false;
5253
if (tabs != null ? !tabs.equals(that.tabs) : that.tabs != null) return false;
53-
return !(executionContext != null ? !executionContext.equals(that.executionContext) : that.executionContext != null);
54-
54+
return executionContext != null ? executionContext.equals(that.executionContext) : that.executionContext == null;
5555
}
5656

5757
@Override
5858
public int hashCode() {
59-
int result = allTabs != null ? allTabs.hashCode() : 0;
59+
int result = super.hashCode();
60+
result = 31 * result + (getUri() != null ? getUri().hashCode() : 0);
61+
result = 31 * result + (allTabs != null ? allTabs.hashCode() : 0);
6062
result = 31 * result + (tabs != null ? tabs.hashCode() : 0);
6163
result = 31 * result + (executionContext != null ? executionContext.hashCode() : 0);
6264
return result;
6365
}
6466

65-
6667
@Override
6768
public String toString() {
6869
return new GoodDataToStringBuilder(this).append("uri", getUri()).toString();

src/main/java/com/gooddata/md/InUseMany.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,21 @@ public InUseMany(Collection<String> uris, boolean nearest, Class<? extends Obj>.
6565
}
6666

6767
@Override
68-
public boolean equals(Object o) {
68+
public boolean equals(final Object o) {
6969
if (this == o) return true;
7070
if (o == null || getClass() != o.getClass()) return false;
7171

72-
InUseMany inUseMany = (InUseMany) o;
72+
final InUseMany inUseMany = (InUseMany) o;
7373

7474
if (nearest != inUseMany.nearest) return false;
75-
if (!types.equals(inUseMany.types)) return false;
76-
if (!uris.equals(inUseMany.uris)) return false;
77-
78-
return true;
75+
if (uris != null ? !uris.equals(inUseMany.uris) : inUseMany.uris != null) return false;
76+
return types != null ? types.equals(inUseMany.types) : inUseMany.types == null;
7977
}
8078

8179
@Override
8280
public int hashCode() {
83-
int result = uris.hashCode();
84-
result = 31 * result + types.hashCode();
81+
int result = uris != null ? uris.hashCode() : 0;
82+
result = 31 * result + (types != null ? types.hashCode() : 0);
8583
result = 31 * result + (nearest ? 1 : 0);
8684
return result;
8785
}

src/main/java/com/gooddata/md/ReportAttachment.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public boolean equals(Object o) {
111111
ReportAttachment that = (ReportAttachment) o;
112112

113113
if (formats != null ? !formats.equals(that.formats) : that.formats != null) return false;
114+
if (getUri() != null ? !getUri().equals(that.getUri()) : that.getUri() != null) return false;
114115
return !(exportOptions != null ? !exportOptions.equals(that.exportOptions) : that.exportOptions != null);
115116

116117
}
@@ -119,6 +120,7 @@ public boolean equals(Object o) {
119120
public int hashCode() {
120121
int result = formats != null ? formats.hashCode() : 0;
121122
result = 31 * result + (exportOptions != null ? exportOptions.hashCode() : 0);
123+
result = 31 * result + (getUri() != null ? getUri().hashCode() : 0);
122124
return result;
123125
}
124126

src/main/java/com/gooddata/project/ProjectValidationResult.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,24 @@ public boolean isWarning() {
7272
}
7373

7474
@Override
75-
public boolean equals(Object o) {
75+
public boolean equals(final Object o) {
7676
if (this == o) return true;
7777
if (o == null || getClass() != o.getClass()) return false;
7878

79-
ProjectValidationResult that = (ProjectValidationResult) o;
79+
final ProjectValidationResult that = (ProjectValidationResult) o;
8080

81-
if (!category.equals(that.category)) return false;
82-
if (!level.equals(that.level)) return false;
83-
if (!message.equals(that.message)) return false;
81+
if (category != null ? !category.equals(that.category) : that.category != null) return false;
82+
if (level != null ? !level.equals(that.level) : that.level != null) return false;
83+
if (message != null ? !message.equals(that.message) : that.message != null) return false;
8484
if (params != null ? !params.equals(that.params) : that.params != null) return false;
85-
if (validation != null ? !validation.equals(that.validation) : that.validation != null) return false;
86-
87-
return true;
85+
return validation != null ? validation.equals(that.validation) : that.validation == null;
8886
}
8987

9088
@Override
9189
public int hashCode() {
92-
int result = category.hashCode();
93-
result = 31 * result + level.hashCode();
94-
result = 31 * result + message.hashCode();
90+
int result = category != null ? category.hashCode() : 0;
91+
result = 31 * result + (level != null ? level.hashCode() : 0);
92+
result = 31 * result + (message != null ? message.hashCode() : 0);
9593
result = 31 * result + (params != null ? params.hashCode() : 0);
9694
result = 31 * result + (validation != null ? validation.hashCode() : 0);
9795
return result;

src/main/java/com/gooddata/project/ProjectValidationResultGdcTimeElParam.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ public List<String> getVals() {
4343
}
4444

4545
@Override
46-
public boolean equals(Object o) {
47-
if (this == o)
48-
return true;
49-
if (!(o instanceof ProjectValidationResultGdcTimeElParam))
50-
return false;
51-
ProjectValidationResultGdcTimeElParam that = (ProjectValidationResultGdcTimeElParam) o;
52-
return Objects.equals(ids, that.ids);
46+
public boolean equals(final Object o) {
47+
if (this == o) return true;
48+
if (o == null || getClass() != o.getClass()) return false;
49+
50+
final ProjectValidationResultGdcTimeElParam that = (ProjectValidationResultGdcTimeElParam) o;
51+
52+
return ids != null ? ids.equals(that.ids) : that.ids == null;
5353
}
5454

5555
@Override
5656
public int hashCode() {
57-
return Objects.hash(ids);
57+
return ids != null ? ids.hashCode() : 0;
5858
}
5959

6060
@Override

src/main/java/com/gooddata/project/ProjectValidationResultObjectParam.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,20 @@ public String toString() {
4141
}
4242

4343
@Override
44-
public boolean equals(Object o) {
44+
public boolean equals(final Object o) {
4545
if (this == o) return true;
4646
if (o == null || getClass() != o.getClass()) return false;
4747

48-
ProjectValidationResultObjectParam that = (ProjectValidationResultObjectParam) o;
48+
final ProjectValidationResultObjectParam that = (ProjectValidationResultObjectParam) o;
4949

50-
if (!name.equals(that.name)) return false;
51-
if (!uri.equals(that.uri)) return false;
52-
53-
return true;
50+
if (name != null ? !name.equals(that.name) : that.name != null) return false;
51+
return uri != null ? uri.equals(that.uri) : that.uri == null;
5452
}
5553

5654
@Override
5755
public int hashCode() {
58-
int result = name.hashCode();
59-
result = 31 * result + uri.hashCode();
56+
int result = name != null ? name.hashCode() : 0;
57+
result = 31 * result + (uri != null ? uri.hashCode() : 0);
6058
return result;
6159
}
6260
}

src/main/java/com/gooddata/project/ProjectValidationResultSliElParam.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,12 @@ public Map<String, String> asMap() {
9191
@Override
9292
public boolean equals(final Object o) {
9393
if (this == o) return true;
94-
if (!(o instanceof ProjectValidationResultSliElParam)) return false;
94+
if (o == null || getClass() != o.getClass()) return false;
9595

96-
ProjectValidationResultSliElParam that = (ProjectValidationResultSliElParam) o;
96+
final ProjectValidationResultSliElParam that = (ProjectValidationResultSliElParam) o;
9797

98-
if (getIds() != null ? !getIds().equals(that.getIds()) : that.getIds() != null) return false;
99-
if (getVals() != null ? !getVals().equals(that.getVals()) : that.getVals() != null) return false;
100-
101-
return true;
98+
if (ids != null ? !ids.equals(that.ids) : that.ids != null) return false;
99+
return vals != null ? vals.equals(that.vals) : that.vals == null;
102100
}
103101

104102
@Override

0 commit comments

Comments
 (0)