Skip to content

Commit

Permalink
Add modified_at timestamp to BoxComment.Info (#501)
Browse files Browse the repository at this point in the history
Fixes #180
  • Loading branch information
Matt Willer authored and iamharish committed Dec 21, 2017
1 parent 0bb73c9 commit 82d2710
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/main/java/com/box/sdk/BoxComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public class Info extends BoxResource.Info {
private Date createdAt;
private BoxResource.Info item;
private BoxUser.Info modifiedBy;
private Date modifiedAt;

/**
* Constructs an empty Info object.
Expand Down Expand Up @@ -222,6 +223,14 @@ public BoxUser.Info getModifiedBy() {
return this.modifiedBy;
}

/**
* Gets the time the comment was last modified.
* @return the time the comment was last modified.
*/
public Date getModifiedAt() {
return this.modifiedAt;
}

@Override
public BoxComment getResource() {
return BoxComment.this;
Expand Down Expand Up @@ -268,6 +277,8 @@ protected void parseJSONMember(JsonObject.Member member) {
} else {
this.modifiedBy.update(userJSON);
}
} else if (memberName.equals("modified_at")) {
this.modifiedAt = BoxDateFormat.parse(value.asString());
}
} catch (ParseException e) {
assert false : "A ParseException indicates a bug in the SDK.";
Expand Down
40 changes: 39 additions & 1 deletion src/test/java/com/box/sdk/BoxCommentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Date;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

import com.eclipsesource.json.JsonObject;
import org.junit.Assert;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.junit.experimental.categories.Category;


public class BoxCommentTest {
@Test
@Category(IntegrationTest.class)
Expand Down Expand Up @@ -95,4 +101,36 @@ public void deleteCommentSucceeds() {

uploadedFile.delete();
}

@Test
@Category(UnitTest.class)
public void testGetCommentInfoIncludesModifiedAt() {

BoxAPIConnection api = new BoxAPIConnection("");
final String commentID = "1234";
final JsonObject commentObj = new JsonObject();
commentObj.add("id", commentID);
commentObj.add("type", "comment");
commentObj.add("modified_at", "1988-11-18T11:18:00-0600");

api.setRequestInterceptor(new RequestInterceptor() {
@Override
public BoxAPIResponse onRequest(BoxAPIRequest request) {
Assert.assertEquals(
"https://api.box.com/2.0/comments/" + commentID,
request.getUrl().toString());
return new BoxJSONResponse() {
@Override
public String getJSON() {
return commentObj.toString();
}
};
}
});

BoxComment comment = new BoxComment(api, commentID);
Date modifiedAtDate = comment.getInfo().getModifiedAt();

assertEquals("18 Nov 1988 17:18:00 GMT", modifiedAtDate.toGMTString());
}
}

0 comments on commit 82d2710

Please sign in to comment.