De-duplicate code for Phabricator result objects
Change-Id: Id0023967d01719164c06d192aa9175d2d21e7062
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/GenericEdit.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/GenericEdit.java
index b01db44..94105c3 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/GenericEdit.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/GenericEdit.java
@@ -47,11 +47,5 @@
public class Transaction extends PhabObject {}
- public class ResultObject extends PhabObject {
- private int id;
-
- public int getId() {
- return id;
- }
- }
+ public class ResultObject extends PhabObjectWithId {}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ManiphestSearch.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ManiphestSearch.java
index e203b2c..48a81e1 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ManiphestSearch.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ManiphestSearch.java
@@ -65,10 +65,4 @@
* }
* </pre>
*/
-public class ManiphestSearch {
- private int id;
-
- public int getId() {
- return id;
- }
-}
+public class ManiphestSearch extends PhabObjectWithId {}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/PhabObject.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/PhabObject.java
index bc2cd46..90c4819 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/PhabObject.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/PhabObject.java
@@ -17,6 +17,14 @@
public class PhabObject {
private String phid;
+ public PhabObject() {
+ this(null);
+ }
+
+ public PhabObject(String phid) {
+ this.phid = phid;
+ }
+
public String getPhid() {
return phid;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/PhabObjectWithId.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/PhabObjectWithId.java
new file mode 100644
index 0000000..dd8c1b9
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/PhabObjectWithId.java
@@ -0,0 +1,32 @@
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.googlesource.gerrit.plugins.its.phabricator.conduit.results;
+
+public class PhabObjectWithId extends PhabObject {
+ private int id;
+
+ public PhabObjectWithId() {
+ super();
+ }
+
+ public PhabObjectWithId(String phid, int id) {
+ super(phid);
+ this.id = id;
+ }
+
+ public int getId() {
+ return id;
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ProjectSearch.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ProjectSearch.java
index f185b36..b4c3d53 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ProjectSearch.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ProjectSearch.java
@@ -56,24 +56,8 @@
* }
* </pre>
*/
-public class ProjectSearch {
- private int id;
- private String phid;
-
- public ProjectSearch(int id, String phid) {
- this.id = id;
- this.phid = phid;
- }
-
- public ProjectSearch() {
- this(0, null);
- }
-
- public int getId() {
- return id;
- }
-
- public String getPhid() {
- return phid;
+public class ProjectSearch extends PhabObjectWithId {
+ public ProjectSearch(String phid, int id) {
+ super(phid, id);
}
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/ConduitTest.java b/src/test/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/ConduitTest.java
index 6a57860..898dbf5 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/ConduitTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/ConduitTest.java
@@ -177,7 +177,7 @@
Conduit conduit = spy(createConduit());
// shortcut the needed project search
- doReturn(new ProjectSearch(12, "PHID-bar")).when(conduit).projectSearch("foo");
+ doReturn(new ProjectSearch("PHID-bar", 12)).when(conduit).projectSearch("foo");
ManiphestEdit actual = conduit.maniphestEdit(4711, null, "foo", null);
@@ -206,7 +206,7 @@
Conduit conduit = spy(createConduit());
// shortcut the needed project search
- doReturn(new ProjectSearch(12, "PHID-bar")).when(conduit).projectSearch("foo");
+ doReturn(new ProjectSearch("PHID-bar", 12)).when(conduit).projectSearch("foo");
ManiphestEdit actual = conduit.maniphestEdit(4711, null, null, "foo");
@@ -243,8 +243,8 @@
Conduit conduit = spy(createConduit());
// shortcut the needed project searches
- doReturn(new ProjectSearch(12, "PHID-bar")).when(conduit).projectSearch("bar");
- doReturn(new ProjectSearch(12, "PHID-baz")).when(conduit).projectSearch("baz");
+ doReturn(new ProjectSearch("PHID-bar", 12)).when(conduit).projectSearch("bar");
+ doReturn(new ProjectSearch("PHID-baz", 13)).when(conduit).projectSearch("baz");
ManiphestEdit actual = conduit.maniphestEdit(4711, "foo", "bar", "baz");