From 36b88a5740ea6ab4764f2153bf3fdee5fd79de47 Mon Sep 17 00:00:00 2001 From: Friedrich Clausen Date: Tue, 15 Jan 2019 11:10:26 +1100 Subject: [PATCH] If a task contains both a comment and a like then parsing would fail This fixes it; used [this diff](https://github.com/cdancy/bitbucket-rest/pull/106/files) for inspiration. --- .../rest/domain/comment/TaskAnchor.java | 6 +++-- .../rest/features/PullRequestApiMockTest.java | 2 ++ .../resources/pull-request-activities.json | 25 +++++++++++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/comment/TaskAnchor.java b/src/main/java/com/cdancy/bitbucket/rest/domain/comment/TaskAnchor.java index 0c02efe6..4b19aaad 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/comment/TaskAnchor.java +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/comment/TaskAnchor.java @@ -21,13 +21,15 @@ import com.cdancy.bitbucket.rest.BitbucketUtils; import com.google.auto.value.AutoValue; import java.util.Map; + +import com.google.gson.JsonElement; import org.jclouds.javax.annotation.Nullable; import org.jclouds.json.SerializedNames; @AutoValue public abstract class TaskAnchor { - public abstract Map properties(); + public abstract Map properties(); public abstract int id(); @@ -53,7 +55,7 @@ public abstract class TaskAnchor { @SerializedNames({ "properties", "id", "version", "text", "author", "createdDate", "updatedDate", "permittedOperations", "type" }) - public static TaskAnchor create(final Map properties, + public static TaskAnchor create(final Map properties, final int id, final int version, final String text, diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/PullRequestApiMockTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/PullRequestApiMockTest.java index f4ca03de..d21308cb 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/PullRequestApiMockTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/PullRequestApiMockTest.java @@ -477,6 +477,8 @@ public void testGetPullRequestActivities() throws Exception { final Task task = comments.tasks().get(0); assertThat(task.anchor().type()).isEqualTo("COMMENT"); assertThat(task.state()).isEqualTo("OPEN"); + assertThat(task.anchor().properties().keySet().contains("likedBy")); + assertThat(task.anchor().properties().keySet().contains("repositoryId")); final Map queryParams = ImmutableMap.of(startKeyword, "0", limitKeyword, 5); assertSent(server, getMethod, restApiPath + BitbucketApiMetadata.API_VERSION diff --git a/src/test/resources/pull-request-activities.json b/src/test/resources/pull-request-activities.json index f6b8b7b6..ec4b9445 100644 --- a/src/test/resources/pull-request-activities.json +++ b/src/test/resources/pull-request-activities.json @@ -68,7 +68,7 @@ "action":"COMMENTED", "commentAction":"ADDED", "comment":{ - "properties":{ + "properties":{ "repositoryId":59 }, "id":1465, @@ -98,7 +98,28 @@ "tasks":[ { "anchor":{ - "properties":{ + "properties":{ + "likedBy": { + "total": 1, + "likers": [ + { + "name": "example_user", + "emailAddress": "user@example.com", + "id": 1, + "displayName": "Example User", + "active": true, + "slug": "example_user", + "type": "NORMAL", + "links": { + "self": [ + { + "href": "http://git.public.io/users/example_user" + } + ] + } + } + ] + }, "repositoryId":59 }, "id":1465,