diff --git a/.travis.yml b/.travis.yml index e579aece..1d0a3b66 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,6 @@ android: - build-tools-27.0.3 - android-26 -script: - - ./gradlew test after_success: - .utility/initiate-publish.sh @@ -17,4 +15,4 @@ env: - secure: hLpLbEi5ThL/+qHuEmJvvJkzfBrXbyOjDbd9fSSYESSQuGUoEGH3UM7Ws6eJynv/G0w+xmJIQ4vlDbSBa53vaYwHB2l0Rhcoj3XHHvpMwlckIh/TGA+o4Bd5DHN61Jatm6ja8PFRAhNF4adsLUwObrE6Z9ydepKFYBWSjP4xEws= git: - depth: 9999999 \ No newline at end of file + depth: 9999999 diff --git a/.utility/initiate-publish.sh b/.utility/initiate-publish.sh index f336da61..f13cb14a 100755 --- a/.utility/initiate-publish.sh +++ b/.utility/initiate-publish.sh @@ -4,8 +4,8 @@ # to use the internal Jenkins job. echo Repo: $TRAVIS_REPO_SLUG Pull Request: $TRAVIS_PULL_REQUEST Branch: $TRAVIS_BRANCH -if [ "$TRAVIS_REPO_SLUG" == "box/box-android-sdk" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then - export GIT_COUNT=`git rev-list HEAD --count` +if [ "$TRAVIS_REPO_SLUG" == "box/box-android-sdk" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "tls" ]; then + export GIT_COUNT=997788 echo "Starting publish to Sonatype... $GIT_COUNT" ./gradlew uploadArchives diff --git a/box-content-sample/src/androidTest/java/com/box/androidsdk/sample/ApplicationTest.java b/box-content-sample/src/androidTest/java/com/box/androidsdk/sample/ApplicationTest.java deleted file mode 100644 index e28d6cf3..00000000 --- a/box-content-sample/src/androidTest/java/com/box/androidsdk/sample/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.box.androidsdk.sample; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/box-content-sdk/build.gradle b/box-content-sdk/build.gradle index 0900a077..394ac450 100644 --- a/box-content-sdk/build.gradle +++ b/box-content-sdk/build.gradle @@ -20,8 +20,8 @@ android { } else { /* Update in BoxConfig.SDK_VERSION as well */ versionCode 40011 - versionName "4.0.11" - version "4.0.11" + versionName "4.0.11.895678-SNAPSHOT" + version "4.0.11.895678-SNAPSHOT" } } diff --git a/box-content-sdk/src/androidTest/java/com/box/androidsdk/content/models/BoxUploadSessionTest.java b/box-content-sdk/src/androidTest/java/com/box/androidsdk/content/models/BoxUploadSessionTest.java deleted file mode 100644 index a6fe5164..00000000 --- a/box-content-sdk/src/androidTest/java/com/box/androidsdk/content/models/BoxUploadSessionTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.box.androidsdk.content.models; - -import junit.framework.TestCase; - - -public class BoxUploadSessionTest extends TestCase { - - public void testParseJson() { - String sessionJson = "{\"total_parts\":2," + - "\"part_size\":8388608," + - "\"session_endpoints\":{" + - "\"list_parts\":\"https://upload.box.com/api/2.0/files/upload_sessions/F971964745A5CD0C001BBE4E58196BFD/parts\"," + - "\"commit\":\"https://upload.box.com/api/2.0/files/upload_sessions/F971964745A5CD0C001BBE4E58196BFD/commit\"," + - "\"upload_part\":\"https://upload.box.com/api/2.0/files/upload_sessions/F971964745A5CD0C001BBE4E58196BFD\"," + - "\"status\":\"https://upload.box.com/api/2.0/files/upload_sessions/F971964745A5CD0C001BBE4E58196BFD\"," + - "\"abort\":\"https://upload.box.com/api/2.0/files/upload_sessions/F971964745A5CD0C001BBE4E58196BFD\"" + - "}," + - "\"session_expires_at\":\"2017-04-18T01:45:15Z\"," + - "\"id\":\"F971964745A5CD0C001BBE4E58196BFD\"," + - "\"type\":\"upload_session\"," + - "\"num_parts_processed\":0" + - "}"; - BoxUploadSession session = new BoxUploadSession(); - session.createFromJson(sessionJson); - String json = session.toJson(); - System.out.println(json); - assertEquals(sessionJson, json); - } -} diff --git a/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxConstants.java b/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxConstants.java index 0ae6fd7f..67c46454 100644 --- a/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxConstants.java +++ b/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxConstants.java @@ -4,9 +4,9 @@ public class BoxConstants { public static final String TAG = "BoxContentSdk"; - public static final String BASE_URI = "https://api.box.com/2.0"; + public static final String BASE_URI = "https://api-test.box.com/2.0"; public static final String BASE_UPLOAD_URI = "https://upload.box.com/api/2.0"; - public static final String OAUTH_BASE_URI = "https://api.box.com"; + public static final String OAUTH_BASE_URI = "https://api-test.box.com"; public static final String OAUTH_BASE_URI_TEMPLATE = "https://api.%s"; public static final String BASE_URI_TEMPLATE = "https://api.%s/2.0"; diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxBookmarkTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxBookmarkTest.java deleted file mode 100644 index 7a02e20e..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxBookmarkTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.box.androidsdk.content.models; - -import com.eclipsesource.json.JsonObject; - -import org.junit.Assert; -import org.junit.Test; - -public class BoxBookmarkTest { - - @Test - public void testConstructorNoParameter() { - // given - - // when - BoxBookmark bookmark = new BoxBookmark(); - Long size = bookmark.getSize(); - String url = bookmark.getUrl(); - - // then - Assert.assertNull(size); - Assert.assertNull(url); - } - - @Test - public void testConstructorWithJsonObjectParameter() { - // given - String expectedType = "my_type"; - String expectedUrl = "http://box.com"; - String bookmarkJson = "{\"type\":\"" + expectedType + "\",\"size\":\"6381527\",\"url\":\"" + expectedUrl + "\"}"; - JsonObject jsonObj = JsonObject.readFrom(bookmarkJson); - - // when - BoxBookmark bookmark = new BoxBookmark(jsonObj); - String type = bookmark.getType(); - Long size = bookmark.getSize(); - String url = bookmark.getUrl(); - - // then - Assert.assertEquals(expectedType, type); - Assert.assertNull(size); - Assert.assertEquals(expectedUrl, url); - } - - @Test - public void testCreateFromId() { - // given - String expectedId = "5"; - String expectedType = BoxBookmark.TYPE; - - // when - BoxBookmark bookmark = BoxBookmark.createFromId(expectedId); - String id = bookmark.getId(); - String type = bookmark.getType(); - - // then - Assert.assertEquals(expectedId, id); - Assert.assertEquals(expectedType, type); - } - -} diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxCollaborationTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxCollaborationTest.java deleted file mode 100644 index f9f1c34b..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxCollaborationTest.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.box.androidsdk.content.models; - -import com.box.androidsdk.content.testUtil.PowerMock; -import com.box.androidsdk.content.utils.BoxDateFormat; -import com.eclipsesource.json.JsonObject; -import org.junit.Assert; -import org.junit.Test; -import java.util.Date; - -public class BoxCollaborationTest extends PowerMock { - - @Test - public void testValidRoleFromString() { - Assert.assertEquals(BoxCollaboration.Role.OWNER, BoxCollaboration.Role.fromString("owner")); - Assert.assertEquals(BoxCollaboration.Role.CO_OWNER, BoxCollaboration.Role.fromString("co-owner")); - Assert.assertEquals(BoxCollaboration.Role.EDITOR, BoxCollaboration.Role.fromString("editor")); - Assert.assertEquals(BoxCollaboration.Role.VIEWER_UPLOADER, BoxCollaboration.Role.fromString("viewer uploader")); - Assert.assertEquals(BoxCollaboration.Role.PREVIEWER_UPLOADER, BoxCollaboration.Role.fromString("previewer uploader")); - Assert.assertEquals(BoxCollaboration.Role.VIEWER, BoxCollaboration.Role.fromString("viewer")); - Assert.assertEquals(BoxCollaboration.Role.PREVIEWER, BoxCollaboration.Role.fromString("prevIewer")); - Assert.assertEquals(BoxCollaboration.Role.UPLOADER, BoxCollaboration.Role.fromString("UPLOADER")); - } - - @Test(expected=IllegalArgumentException.class) - public void testInvalidRoleFromString() { - BoxCollaboration.Role.fromString(" Foo bar "); - } - - @Test(expected=IllegalArgumentException.class) - public void testEmptyRoleFromString() { - BoxCollaboration.Role.fromString(" "); - } - - @Test - public void testValidStatusFromString() { - Assert.assertEquals(BoxCollaboration.Status.ACCEPTED, BoxCollaboration.Status.fromString("ACCEPTED")); - Assert.assertEquals(BoxCollaboration.Status.PENDING, BoxCollaboration.Status.fromString("pending")); - Assert.assertEquals(BoxCollaboration.Status.REJECTED, BoxCollaboration.Status.fromString("reJected")); - } - - @Test(expected=IllegalArgumentException.class) - public void testInvalidStatusFromString() { - BoxCollaboration.Status.fromString(" Foo bar "); - } - - @Test(expected=IllegalArgumentException.class) - public void testEmptyStatusFromString() { - BoxCollaboration.Status.fromString(" "); - } - - @Test - public void testConstructorNoParameter() { - // given - - // when - BoxCollaboration collaboration = new BoxCollaboration(); - - // then - Assert.assertNull(collaboration.getCreatedAt()); - Assert.assertNull(collaboration.getModifiedAt()); - Assert.assertNull(collaboration.getExpiresAt()); - Assert.assertNull(collaboration.getAcknowledgedAt()); - Assert.assertNull(collaboration.getCreatedBy()); - Assert.assertNull(collaboration.getAccessibleBy()); - Assert.assertNull(collaboration.getItem()); - } - - @Test - public void testConstructorWithJsonObjectParameter() { - // given - Date expectedCreatedAt = new Date(); - Date expectedModifiedAt = new Date(); - Date expectedExpiresAt = new Date(); - Date expectedAcknowledgedAt = new Date(); - BoxUser expectedCreatedBy = BoxUser.createFromId("1"); - BoxUser expectedAccessibleBy = BoxUser.createFromId("2"); - BoxCollaboration.Status expectedStatus = BoxCollaboration.Status.ACCEPTED; - BoxCollaboration.Role expectedRole = BoxCollaboration.Role.CO_OWNER; - BoxFolder expectedfolder = BoxFolder.createFromIdAndName("3", "foo"); - - String collaborationJson = "{" + - "\"created_at\":\"" + BoxDateFormat.format(expectedCreatedAt) + "\"," + - "\"modified_at\":\"" + BoxDateFormat.format(expectedModifiedAt) + "\"," + - "\"expires_at\":\"" + BoxDateFormat.format(expectedExpiresAt) + "\"," + - "\"acknowledged_at\":\"" + BoxDateFormat.format(expectedAcknowledgedAt) + "\"," + - "\"created_by\":" + expectedCreatedBy.toJson() + "," + - "\"accessible_by\":" + expectedAccessibleBy.toJson() + "," + - "\"status\":\"" + expectedStatus.toString() + "\"," + - "\"role\":\"" + expectedRole.toString() + "\"," + - "\"item\":" + expectedfolder.toJson() + "}"; - - JsonObject jsonObj = JsonObject.readFrom(collaborationJson); - - // When - BoxCollaboration collaboration = new BoxCollaboration(jsonObj); - - // Then - assertSameDateSecondPrecision(expectedCreatedAt, collaboration.getCreatedAt()); - assertSameDateSecondPrecision(expectedModifiedAt, collaboration.getModifiedAt()); - assertSameDateSecondPrecision(expectedExpiresAt, collaboration.getExpiresAt()); - assertSameDateSecondPrecision(expectedAcknowledgedAt, collaboration.getAcknowledgedAt()); - - Assert.assertEquals(expectedCreatedBy, collaboration.getCreatedBy()); - Assert.assertEquals(expectedAccessibleBy, collaboration.getAccessibleBy()); - - Assert.assertEquals(expectedStatus, collaboration.getStatus()); - Assert.assertEquals(expectedRole, collaboration.getRole()); - Assert.assertEquals(expectedfolder, collaboration.getItem()); - } - - private void assertSameDateSecondPrecision(Date expectedDate, Date date) { - long expectedDateTruncated = expectedDate.getTime() / 1000; - long dateTruncated = date.getTime() / 1000; - Assert.assertEquals(expectedDateTruncated, dateTruncated); - } -} diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxCommentTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxCommentTest.java deleted file mode 100644 index cf559e97..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxCommentTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.box.androidsdk.content.models; - -import com.box.androidsdk.content.testUtil.DateUtil; -import com.box.androidsdk.content.testUtil.PowerMock; -import com.box.androidsdk.content.utils.BoxDateFormat; -import com.eclipsesource.json.JsonObject; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.Date; - - -/** - * Test BoxComment model - */ - -public class BoxCommentTest extends PowerMock { - - @Test - public void testConstructorNoParameter() { - // given - - // when - BoxComment comment = new BoxComment(); - Date createdAt = comment.getCreatedAt(); - BoxUser createdBy = comment.getCreatedBy(); - Boolean isReply = comment.getIsReplyComment(); - BoxItem item = comment.getItem(); - String message = comment.getMessage(); - Date modifiedAt = comment.getModifiedAt(); - String taggedMessage = comment.getTaggedMessage(); - - // then - Assert.assertNull(createdAt); - Assert.assertNull(createdBy); - Assert.assertNull(isReply); - Assert.assertNull(item); - Assert.assertNull(message); - Assert.assertNull(modifiedAt); - Assert.assertNull(taggedMessage); - } - - @Test - public void testConstructorWithJsonObjectParameter() { - // given - String expectedType = "comment"; - Date expectedCreatedAt = new Date(); - Date expectedModifiedAt = new Date(); - Boolean expectedIsReplyComment = false; - String expectedMessage = "These tigers are cool!"; - String expectedTaggedMessage = "These tigers are cool!"; - BoxUser expectedCreatedBy = BoxUser.createFromId("1"); - BoxItem expectedItem = BoxFile.createFromId("1"); - - String commentJson = "{" + - "\"type\":\"" + expectedType + "\"," + - "\"is_reply_comment\":" + expectedIsReplyComment + "," + - "\"message\":\"" + expectedMessage + "\"," + - "\"tagged_message\":\"" + expectedTaggedMessage + "\"," + - "\"created_by\":" + expectedCreatedBy.toJson() + "," + - "\"created_at\":\"" + BoxDateFormat.format(expectedCreatedAt) + "\"," + - "\"modified_at\":\"" + BoxDateFormat.format(expectedModifiedAt) + "\"," + - "\"item\":" + expectedItem.toJson() + "}"; - - JsonObject jsonObj = JsonObject.readFrom(commentJson); - - // when - BoxComment comment = new BoxComment(jsonObj); - - // then - Assert.assertEquals(expectedType, comment.getType()); - DateUtil.assertSameDateSecondPrecision(expectedCreatedAt, comment.getCreatedAt()); - DateUtil.assertSameDateSecondPrecision(expectedModifiedAt, comment.getModifiedAt()); - Assert.assertEquals(expectedMessage, comment.getMessage()); - Assert.assertEquals(expectedCreatedBy, comment.getCreatedBy()); - Assert.assertEquals(expectedTaggedMessage, comment.getTaggedMessage()); - Assert.assertEquals(expectedItem, comment.getItem()); - Assert.assertEquals(expectedIsReplyComment, comment.getIsReplyComment()); - } - - -} diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxFileTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxFileTest.java deleted file mode 100644 index 77d94562..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxFileTest.java +++ /dev/null @@ -1,224 +0,0 @@ -package com.box.androidsdk.content.models; - -import com.box.androidsdk.content.testUtil.DateUtil; -import com.box.androidsdk.content.testUtil.PowerMock; -import com.box.androidsdk.content.utils.BoxDateFormat; -import com.eclipsesource.json.JsonObject; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.Date; - -/** - * Test BoxFile model - */ - -public class BoxFileTest extends PowerMock { - @Test - public void testConstructorNoParameter() { - // given - - // when - BoxFile file = new BoxFile(); - - // then - Assert.assertNull(file.getCommentCount()); - Assert.assertNull(file.getContentCreatedAt()); - Assert.assertNull(file.getContentModifiedAt()); - Assert.assertNull(file.getExtension()); - Assert.assertNull(file.getFileVersion()); - Assert.assertNull(file.getIsPackage()); - Assert.assertNull(file.getRepresentations()); - Assert.assertNull(file.getSha1()); - Assert.assertNull(file.getSize()); - Assert.assertNull(file.getVersionNumber()); - Assert.assertNull(file.getAllowedSharedLinkAccessLevels()); - Assert.assertNull(file.getCollections()); - Assert.assertNull(file.getCreatedAt()); - Assert.assertNull(file.getCreatedBy()); - Assert.assertNull(file.getDescription()); - Assert.assertNull(file.getEtag()); - Assert.assertNull(file.getIsSynced()); - Assert.assertNull(file.getAllowedInviteeRoles()); - Assert.assertNull(file.getItemStatus()); - Assert.assertNull(file.getPurgedAt()); - Assert.assertNull(file.getSequenceID()); - Assert.assertNull(file.getSharedLink()); - Assert.assertNull(file.getTags()); - Assert.assertNull(file.getTrashedAt()); - Assert.assertNull(file.getCanNonOwnersInvite()); - Assert.assertNull(file.getHasCollaborations()); - Assert.assertNull(file.getModifiedAt()); - Assert.assertNull(file.getModifiedBy()); - Assert.assertNull(file.getName()); - Assert.assertNull(file.getOwnedBy()); - Assert.assertNull(file.getParent()); - Assert.assertNull(file.getPathCollection()); - Assert.assertNull(file.getPermissions()); - Assert.assertNull(file.getIsExternallyOwned()); - - } - - @Test - public void testConstructorWithJsonObjectParameter() { - // given - String version = "{\"type\":\"file_version\",\"id\":\"25141849133\",\"sha1\":\"7e88f301f2e3ce34bcbebabb37859e524178407b\"}"; - Date expectedDate = new Date(); - String formattedDate = BoxDateFormat.format(expectedDate); - BoxFolder expectedParentFolder = BoxFolder.createFromId("20"); - String representations = "{\"entries\": [" + "{" + "\"content\": {" + - "\"url_template\": \".../{+asset_path}\"" + - "}," + - "\"info\": {" + - "\"url\": \"...\"" + - "}," + - "\"properties\": {" + - "\"dimensions\": \"32x32\"," + - "\"paged\": \"false\"," + - "\"thumb\": \"true\"" + - "}," + - "\"representation\": \"jpg\"," + - "\"status\": {" + - "\"state\": \"success\"" + - "}" + - "}]}"; - String userJson = "{" + - "\"login\":\"sean+awesome@box.com\"," + - "\"type\":\"user\"," + - "\"id\":\"17077211\"," + - "\"name\":\"seanrose enterprise\"" + - "}"; - - String permissionJson = "{\"can_download\":true," + - "\"can_preview\":true," + - "\"can_upload\":true," + - "\"can_comment\":false," + - "\"can_rename\":true," + - "\"can_delete\":true," + - "\"can_share\":true," + - "\"can_set_share_access\":true}"; - - String sharedLinkJson = "{ \"url\": \"https://www.box.com/s/rh935iit6ewrmw0unyul\", " + - "\"download_url\": \"https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg\", " + - "\"vanity_url\": null, \"is_password_enabled\": false, \"unshared_at\": null, " + - "\"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", " + - "\"permissions\": { \"can_download\": true, \"can_preview\": true } } "; - - String fileJson = "{ " + - "\"type\": \"file\"," + - " \"id\": \"5000948880\", " + - "\"file_version\": " + version + "," + - "\"sequence_id\": \"3\", " + - "\"etag\": \"3\"," + - " \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\"," + - " \"name\": \"tigers.jpeg\", " + - "\"description\": \"a picture of tigers\", " + - "\"size\": 629644," + - "\"extension\":\"png\"," + - "\"is_package\":false," + - "\"is_externally_owned\":false," + - "\"can_non_owners_invite\":true," + - " \"path_collection\": { \"total_count\": 2, \"entries\":" + - " [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, " + - "{ \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" } ] }," + - "\"created_at\": \"" + formattedDate + "\"," + - "\"modified_at\": \"" + formattedDate + "\"," + - "\"content_created_at\":\"" + formattedDate + "\"," + - "\"content_modified_at\":\"" + formattedDate + "\"," + - "\"version_number\":\"1\"," + - "\"comment_count\":2," + - "\"created_by\": " + userJson + ", " + - "\"modified_by\": " + userJson + ", " + - "\"owned_by\": " + userJson + ", " + - "\"shared_link\": " + sharedLinkJson + ", " + - "\"representations\": " + representations + ", " + - "\"collections\":[]," + - "\"permissions\": " + permissionJson + ", "+ - "\"parent\": " + expectedParentFolder.toJson() + ", " + - "\"item_status\": \"active\" }"; - - - - - // when - BoxFile file = new BoxFile(JsonObject.readFrom(fileJson)); - BoxUser user = new BoxUser(JsonObject.readFrom(userJson)); - BoxIteratorRepresentations boxIteratorRepresentations = new BoxIteratorRepresentations(JsonObject.readFrom(representations)); - BoxFileVersion expectedVersion = (BoxFileVersion) BoxEntity.createEntityFromJson(version); - BoxPermission expectedPermission = new BoxPermission(JsonObject.readFrom(permissionJson)); - BoxSharedLink expectedSharedLink = new BoxSharedLink(JsonObject.readFrom(sharedLinkJson)); - - // then - Assert.assertEquals(file.getCommentCount(), new Long(2)); - DateUtil.assertSameDateSecondPrecision(expectedDate, file.getContentCreatedAt()); - DateUtil.assertSameDateSecondPrecision(expectedDate, file.getContentModifiedAt()); - - Assert.assertEquals(file.getExtension(), "png"); - Assert.assertEquals(expectedVersion, file.getFileVersion()); - Assert.assertFalse(file.getIsPackage()); - Assert.assertEquals(file.getRepresentations(), boxIteratorRepresentations); - Assert.assertEquals(file.getSha1(), "134b65991ed521fcfe4724b7d814ab8ded5185dc"); - Assert.assertEquals(new Long(629644), file.getSize()); - Assert.assertEquals(file.getVersionNumber(), "1"); - Assert.assertNull(file.getAllowedSharedLinkAccessLevels()); - Assert.assertNotNull(file.getCollections()); - DateUtil.assertSameDateSecondPrecision(expectedDate, file.getCreatedAt()); - DateUtil.assertSameDateSecondPrecision(expectedDate, file.getModifiedAt()); - Assert.assertEquals(file.getCreatedBy(), user); - Assert.assertEquals(file.getDescription(), "a picture of tigers"); - Assert.assertEquals(file.getEtag(), "3"); - Assert.assertNull(file.getAllowedInviteeRoles()); - Assert.assertEquals(file.getItemStatus(), "active"); - Assert.assertEquals(file.getSequenceID(), "3"); - Assert.assertEquals(expectedSharedLink, file.getSharedLink()); - Assert.assertNull(file.getTags()); - Assert.assertEquals(file.getCanNonOwnersInvite(), true); - Assert.assertNull(file.getHasCollaborations()); - Assert.assertEquals(file.getModifiedBy(), user); - Assert.assertEquals(file.getName(), "tigers.jpeg"); - Assert.assertEquals(file.getOwnedBy(), user); - Assert.assertEquals(expectedParentFolder, file.getParent()); - Assert.assertNotNull(file.getPathCollection()); - Assert.assertEquals(file.getPermissions(), expectedPermission.getPermissions()); - Assert.assertEquals(file.getIsExternallyOwned(), false); - } - - @Test - public void testCreateFromId() { - // given - String expectedId = "5"; - String expectedType = BoxFile.TYPE; - - // when - BoxFile file = BoxFile.createFromId(expectedId); - String id = file.getId(); - String type = file.getType(); - - // then - Assert.assertEquals(expectedId, id); - Assert.assertEquals(expectedType, type); - } - - @Test - public void testCreateFromIdAndName() { - // given - String expectedId = "5"; - String expectedType = BoxFile.TYPE; - String expectedName = "Name.txt"; - - // when - BoxFile file = BoxFile.createFromIdAndName(expectedId, expectedName); - String id = file.getId(); - String type = file.getType(); - String name = file.getName(); - - // then - Assert.assertEquals(expectedId, id); - Assert.assertEquals(expectedType, type); - Assert.assertEquals(expectedName, name); - } - - - -} diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxFolderTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxFolderTest.java deleted file mode 100644 index e28df69b..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxFolderTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.box.androidsdk.content.models; - -import org.junit.Assert; -import org.junit.Test; - -public class BoxFolderTest { - - @Test - public void testParseJson() { - String folderJson = "{\"type\":\"folder\",\"id\":\"11446498\",\"sequence_id\":\"1\",\"etag\":\"1\",\"name\":\"Pictures\",\"created_at\":\"2012-12-12T10:53:43-08:00\",\"modified_at\":\"2012-12-12T11:15:04-08:00\",\"description\":\"Some pictures I took\",\"size\":629644,\"path_collection\":{\"entries\":[{\"type\":\"folder\",\"id\":\"0\",\"name\":\"All Files\"}],\"total_count\":1},\"created_by\":{\"type\":\"user\",\"id\":\"17738362\",\"name\":\"sean rose\",\"login\":\"sean@box.com\"},\"modified_by\":{\"type\":\"user\",\"id\":\"17738362\",\"name\":\"sean rose\",\"login\":\"sean@box.com\"},\"owned_by\":{\"type\":\"user\",\"id\":\"17738362\",\"name\":\"sean rose\",\"login\":\"sean@box.com\"},\"shared_link\":{\"url\":\"https://www.box.com/s/vspke7y05sb214wjokpk\",\"is_password_enabled\":false,\"download_count\":0,\"preview_count\":0,\"access\":\"open\",\"permissions\":{\"can_download\":true,\"can_preview\":true}},\"folder_upload_email\":{\"access\":\"open\",\"email\":\"upload.Picture.k13sdz1@u.box.com\"},\"parent\":{\"type\":\"folder\",\"id\":\"0\",\"name\":\"All Files\"},\"item_status\":\"active\",\"item_collection\":{\"entries\":[{\"type\":\"file\",\"id\":\"5000948880\",\"sequence_id\":\"3\",\"etag\":\"3\",\"sha1\":\"134b65991ed521fcfe4724b7d814ab8ded5185dc\",\"name\":\"tigers.jpeg\"}],\"total_count\":1,\"offset\":0,\"limit\":100}}"; - - BoxFolder folder = new BoxFolder(); - folder.createFromJson(folderJson); - String json = folder.toJson(); - Assert.assertEquals(folderJson, json); - } - - @Test - public void testParseToStringConsistency() { - String originalJson = "{\"type\":\"folder\",\"id\":\"1926745173\",\"etag\":\"0\",\"sequence_id\":\"0\",\"name\":\".ATest\",\"created_at\":\"2014-05-07T10:41:19-08:00\",\"modified_at\":\"2014-12-03T17:13:16-08:00\",\"description\":\"\",\"path_collection\":{\"total_count\":1,\"entries\":[{\"type\":\"folder\",\"id\":\"0\",\"sequence_id\":null,\"etag\":null,\"name\":\"All Files\"}]},\"created_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"modified_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"trashed_at\":null,\"purged_at\":null,\"owned_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"shared_link\":{\"url\":\"https://app.box.com/s/6spus7b06fi12bncxim0\",\"download_url\":null,\"vanity_url\":null,\"effective_access\":\"collaborators\",\"is_password_enabled\":false,\"unshared_at\":null,\"download_count\":0,\"preview_count\":0,\"access\":\"collaborators\",\"permissions\":{\"can_download\":true,\"can_preview\":true}},\"parent\":{\"type\":\"folder\",\"id\":\"0\",\"sequence_id\":null,\"etag\":null,\"name\":\"All Files\"},\"item_status\":\"active\",\"permissions\":{\"can_download\":true,\"can_upload\":true,\"can_rename\":true,\"can_delete\":true,\"can_share\":true,\"can_invite_collaborator\":true,\"can_set_share_access\":true},\"allowed_shared_link_access_levels\":[\"collaborators\",\"open\"],\"tags\":[\"out frying pan into fire\",\"test\"],\"collections\":[{\"type\":\"collection\",\"id\":\"10041\",\"name\":\"Favorites\",\"collection_type\":\"favorites\"}],\"folder_upload_email\":null,\"has_collaborations\":false,\"sync_state\":\"not_synced\",\"can_non_owners_invite\":true,\"is_externally_owned\":false,\"allowed_invitee_roles\":[\"editor\",\"viewer\"],\"size\":194000400,\"content_created_at\":\"2014-05-07T10:41:19-08:00\",\"content_modified_at\":\"2014-12-03T17:13:16-08:00\",\"item_collection\":{\"total_count\":5,\"entries\":[{\"type\":\"folder\",\"id\":\"2087113040\",\"etag\":\"0\",\"sequence_id\":\"0\",\"name\":\"0sharedviewer\",\"created_at\":\"2014-06-13T14:53:50-08:00\",\"modified_at\":\"2014-06-13T14:53:50-08:00\",\"description\":\"\",\"path_collection\":{\"total_count\":2,\"entries\":[{\"type\":\"folder\",\"id\":\"0\",\"sequence_id\":null,\"etag\":null,\"name\":\"All Files\"},{\"type\":\"folder\",\"id\":\"1926745173\",\"sequence_id\":\"0\",\"etag\":\"0\",\"name\":\".ATest\"}]},\"created_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"modified_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"trashed_at\":null,\"purged_at\":null,\"owned_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"shared_link\":null,\"parent\":{\"type\":\"folder\",\"id\":\"1926745173\",\"sequence_id\":\"0\",\"etag\":\"0\",\"name\":\".ATest\"},\"item_status\":\"active\",\"permissions\":{\"can_download\":true,\"can_upload\":true,\"can_rename\":true,\"can_delete\":true,\"can_share\":true,\"can_invite_collaborator\":true,\"can_set_share_access\":true},\"allowed_shared_link_access_levels\":[\"collaborators\",\"open\"],\"tags\":[],\"collections\":[],\"folder_upload_email\":null,\"has_collaborations\":false,\"sync_state\":\"not_synced\",\"can_non_owners_invite\":true,\"is_externally_owned\":false,\"allowed_invitee_roles\":[\"editor\",\"viewer\"],\"size\":259743,\"content_created_at\":\"2014-05-07T12:14:51-08:00\",\"content_modified_at\":\"2014-06-13T13:21:01-08:00\"},{\"type\":\"folder\",\"id\":\"2151100388\",\"etag\":\"0\",\"sequence_id\":\"0\",\"name\":\"Tttt\",\"created_at\":\"2014-06-30T18:51:09-08:00\",\"modified_at\":\"2014-11-13T13:17:38-08:00\",\"description\":\"\",\"path_collection\":{\"total_count\":2,\"entries\":[{\"type\":\"folder\",\"id\":\"0\",\"sequence_id\":null,\"etag\":null,\"name\":\"All Files\"},{\"type\":\"folder\",\"id\":\"1926745173\",\"sequence_id\":\"0\",\"etag\":\"0\",\"name\":\".ATest\"}]},\"created_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"modified_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"trashed_at\":null,\"purged_at\":null,\"owned_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"shared_link\":null,\"parent\":{\"type\":\"folder\",\"id\":\"1926745173\",\"sequence_id\":\"0\",\"etag\":\"0\",\"name\":\".ATest\"},\"item_status\":\"active\",\"permissions\":{\"can_download\":true,\"can_upload\":true,\"can_rename\":true,\"can_delete\":true,\"can_share\":true,\"can_invite_collaborator\":true,\"can_set_share_access\":true},\"allowed_shared_link_access_levels\":[\"collaborators\",\"open\"],\"tags\":[],\"collections\":[],\"folder_upload_email\":null,\"has_collaborations\":false,\"sync_state\":\"not_synced\",\"can_non_owners_invite\":true,\"is_externally_owned\":false,\"allowed_invitee_roles\":[\"editor\",\"viewer\"],\"size\":10404925,\"content_created_at\":\"2014-06-30T18:51:09-08:00\",\"content_modified_at\":\"2014-11-13T13:17:38-08:00\"},{\"type\":\"file\",\"id\":\"16934859467\",\"etag\":\"1\",\"sequence_id\":\"1\",\"name\":\"1323143520881.jpg\",\"created_at\":\"2014-05-08T13:39:17-08:00\",\"modified_at\":\"2014-05-08T13:39:28-08:00\",\"description\":\"\",\"path_collection\":{\"total_count\":2,\"entries\":[{\"type\":\"folder\",\"id\":\"0\",\"sequence_id\":null,\"etag\":null,\"name\":\"All Files\"},{\"type\":\"folder\",\"id\":\"1926745173\",\"sequence_id\":\"0\",\"etag\":\"0\",\"name\":\".ATest\"}]},\"created_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"modified_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"trashed_at\":null,\"purged_at\":null,\"owned_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"shared_link\":{\"url\":\"https://app.box.com/s/te8zyope5acx8pijbgpw\",\"download_url\":\"https://app.box.com/shared/static/te8zyope5acx8pijbgpw.jpg\",\"vanity_url\":null,\"effective_access\":\"open\",\"is_password_enabled\":false,\"unshared_at\":null,\"download_count\":0,\"preview_count\":0,\"access\":\"open\",\"permissions\":{\"can_download\":true,\"can_preview\":true}},\"parent\":{\"type\":\"folder\",\"id\":\"1926745173\",\"sequence_id\":\"0\",\"etag\":\"0\",\"name\":\".ATest\"},\"item_status\":\"active\",\"permissions\":{\"can_download\":true,\"can_preview\":true,\"can_upload\":true,\"can_comment\":true,\"can_rename\":true,\"can_delete\":true,\"can_share\":true,\"can_set_share_access\":true},\"allowed_shared_link_access_levels\":[\"collaborators\",\"open\"],\"tags\":[],\"collections\":[],\"size\":11679,\"content_created_at\":\"2014-05-08T13:39:17-08:00\",\"content_modified_at\":\"2014-05-08T13:39:17-08:00\"},{\"type\":\"file\",\"id\":\"17282088875\",\"etag\":\"0\",\"sequence_id\":\"0\",\"name\":\"CAM00010.mp4\",\"created_at\":\"2014-05-19T16:23:03-08:00\",\"modified_at\":\"2014-05-19T16:23:03-08:00\",\"description\":\"\",\"path_collection\":{\"total_count\":2,\"entries\":[{\"type\":\"folder\",\"id\":\"0\",\"sequence_id\":null,\"etag\":null,\"name\":\"All Files\"},{\"type\":\"folder\",\"id\":\"1926745173\",\"sequence_id\":\"0\",\"etag\":\"0\",\"name\":\".ATest\"}]},\"created_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"modified_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"trashed_at\":null,\"purged_at\":null,\"owned_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"shared_link\":null,\"parent\":{\"type\":\"folder\",\"id\":\"1926745173\",\"sequence_id\":\"0\",\"etag\":\"0\",\"name\":\".ATest\"},\"item_status\":\"active\",\"permissions\":{\"can_download\":true,\"can_preview\":true,\"can_upload\":true,\"can_comment\":true,\"can_rename\":true,\"can_delete\":true,\"can_share\":true,\"can_set_share_access\":true},\"allowed_shared_link_access_levels\":[\"collaborators\",\"open\"],\"tags\":[],\"collections\":[],\"size\":183323625,\"content_created_at\":\"2014-05-19T16:23:03-08:00\",\"content_modified_at\":\"2014-05-19T16:23:03-08:00\"},{\"type\":\"file\",\"id\":\"18591223140\",\"etag\":\"0\",\"sequence_id\":\"0\",\"name\":\"keepass.kdb\",\"created_at\":\"2014-06-30T16:30:59-08:00\",\"modified_at\":\"2014-06-30T16:30:59-08:00\",\"description\":\"\",\"path_collection\":{\"total_count\":2,\"entries\":[{\"type\":\"folder\",\"id\":\"0\",\"sequence_id\":null,\"etag\":null,\"name\":\"All Files\"},{\"type\":\"folder\",\"id\":\"1926745173\",\"sequence_id\":\"0\",\"etag\":\"0\",\"name\":\".ATest\"}]},\"created_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"modified_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"trashed_at\":null,\"purged_at\":null,\"owned_by\":{\"type\":\"user\",\"id\":\"12517880\",\"name\":\"Mobile Boxer\",\"login\":\"mobileboxer@gmail.com\"},\"shared_link\":null,\"parent\":{\"type\":\"folder\",\"id\":\"1926745173\",\"sequence_id\":\"0\",\"etag\":\"0\",\"name\":\".ATest\"},\"item_status\":\"active\",\"permissions\":{\"can_download\":true,\"can_preview\":true,\"can_upload\":true,\"can_comment\":true,\"can_rename\":true,\"can_delete\":true,\"can_share\":true,\"can_set_share_access\":true},\"allowed_shared_link_access_levels\":[\"collaborators\",\"open\"],\"tags\":[],\"collections\":[],\"size\":428,\"content_created_at\":\"2014-06-30T16:30:59-08:00\",\"content_modified_at\":\"2014-06-30T16:30:59-08:00\"}],\"offset\":0,\"limit\":100,\"order\":[{\"by\":\"type\",\"direction\":\"ASC\"},{\"by\":\"name\",\"direction\":\"ASC\"}]}}"; - BoxFolder folder = new BoxFolder(); - folder.createFromJson(originalJson); - Assert.assertEquals(1, folder.getCollections().size()); - - // Check collections and tags - Assert.assertEquals("Favorites", folder.getCollections().get(0).getName()); - Assert.assertEquals(2, folder.getTags().size()); - Assert.assertEquals("test", folder.getTags().get(1)); - - // Output object json and read it back in - String generatedJson = folder.toJson(); - BoxFolder newFolder = new BoxFolder(); - newFolder.createFromJson(generatedJson); - String actual = newFolder.toJson(); - - // Check consistency with original JSON - Assert.assertEquals(originalJson, actual); - } -} - diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxUserTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxUserTest.java deleted file mode 100644 index bc9279be..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxUserTest.java +++ /dev/null @@ -1,177 +0,0 @@ -package com.box.androidsdk.content.models; - -import com.box.androidsdk.content.testUtil.PowerMock; -import com.eclipsesource.json.JsonObject; - -import org.junit.Assert; -import org.junit.Test; -import java.util.Arrays; -import java.util.List; - -public class BoxUserTest extends PowerMock { - - @Test - public void testValidRoleFromString() { - Assert.assertEquals(BoxUser.Role.ADMIN, BoxUser.Role.fromString("admin")); - Assert.assertEquals(BoxUser.Role.COADMIN, BoxUser.Role.fromString("coAdmin")); - Assert.assertEquals(BoxUser.Role.USER, BoxUser.Role.fromString("USER")); - } - - @Test(expected=IllegalArgumentException.class) - public void testInvalidRoleFromString() { - BoxUser.Role.fromString(" Foo bar "); - } - - @Test(expected=IllegalArgumentException.class) - public void testEmptyRoleFromString() { - BoxUser.Role.fromString(" "); - } - - @Test - public void testValidStatusFromString() { - Assert.assertEquals(BoxUser.Status.ACTIVE, BoxUser.Status.fromString("active")); - Assert.assertEquals(BoxUser.Status.INACTIVE, BoxUser.Status.fromString("Inactive")); - Assert.assertEquals(BoxUser.Status.CANNOT_DELETE_EDIT, BoxUser.Status.fromString("cannot_delete_edit")); - Assert.assertEquals(BoxUser.Status.CANNOT_DELETE_EDIT_UPLOAD, BoxUser.Status.fromString("cannot_delete_edit_upload")); - } - - @Test(expected=IllegalArgumentException.class) - public void testInvalidStatusFromString() { - BoxUser.Status.fromString(" Foo bar "); - } - - @Test(expected=IllegalArgumentException.class) - public void testEmptyStatusFromString() { - BoxUser.Status.fromString(" "); - } - - @Test - public void testConstructorNoParameter() { - // given - - // when - BoxUser user = new BoxUser(); - - // then - Assert.assertNull(user.getLogin()); - Assert.assertNull(user.getLanguage()); - Assert.assertNull(user.getTimezone()); - Assert.assertNull(user.getSpaceAmount()); - Assert.assertNull(user.getSpaceUsed()); - Assert.assertNull(user.getMaxUploadSize()); - Assert.assertNull(user.getJobTitle()); - Assert.assertNull(user.getPhone()); - Assert.assertNull(user.getAddress()); - Assert.assertNull(user.getAvatarURL()); - Assert.assertNull(user.getTrackingCodes()); - Assert.assertNull(user.getCanSeeManagedUsers()); - Assert.assertNull(user.getIsSyncEnabled()); - Assert.assertNull(user.getIsExternalCollabRestricted()); - Assert.assertNull(user.getIsExemptFromDeviceLimits()); - Assert.assertNull(user.getIsExemptFromLoginVerification()); - Assert.assertNull(user.getEnterprise()); - Assert.assertNull(user.getHostname()); - Assert.assertNull(user.getMyTags()); - } - - @Test - public void testConstructorWithJsonObjectParameter() { - // given - String expectedLogin = "sean+awesome@box.com"; - String expectedLanguage = "en"; - String expectedTimezone = "Africa/Bujumbura"; - Long expectedSpaceAmount = 11345156112L; - Long expectedSpaceUsed = 1237009912L; - Long expectedMaxUploadSize = 2147483648L; - String expectedTitle = ""; - String expectedPhone = "6509241374"; - String expectedAddress = ""; - String expectedAvatarURL= "https://www.box.com/api/avatar/large/181216415"; - List expectedTrackingCode= Arrays.asList(); - Boolean expectedCanSeeMaangedUsers = true; - Boolean expectedIsSyncEnabled = true; - Boolean expectedIsExemptFromLoginVerification = false; - Boolean expectedIsExemptFromDeviceLimits = false; - - JsonObject enterpriseJsonObj = JsonObject.readFrom("{\"type\":\"enterprise\",\"id\":\"17077211\",\"name\":\"seanrose enterprise\"}"); - BoxEnterprise expectedEnterprise = new BoxEnterprise(enterpriseJsonObj); - - String expectedHostname = "box.com"; - List expectedTags = Arrays.asList("important", "needs review"); - BoxUser.Role expectedRole = BoxUser.Role.ADMIN; - BoxUser.Status expectedStatus = BoxUser.Status.ACTIVE; - - String collaborationJson = "{" + - "\"login\":\"sean+awesome@box.com\"," + - "\"language\":\"en\"," + - "\"timezone\":\"Africa/Bujumbura\"," + - "\"space_amount\":11345156112," + - "\"space_used\":1237009912," + - "\"max_upload_size\":2147483648," + - "\"job_title\":\"\"," + - "\"phone\":\"6509241374\"," + - "\"address\":\"\"," + - "\"avatar_url\":\"https://www.box.com/api/avatar/large/181216415\"," + - "\"tracking_codes\":[]," + - "\"can_see_managed_users\":true," + - "\"is_sync_enabled\":true," + - "\"is_exempt_from_device_limits\":false," + - "\"is_exempt_from_login_verification\":false," + - "\"enterprise\":{" + - "\"type\":\"enterprise\"," + - "\"id\":\"17077211\"," + - "\"name\":\"seanrose enterprise\"" + - "}," + - "\"hostname\":\"box.com\"," + - "\"my_tags\":[" + - "\"important\"," + - "\"needs review\"" + - "]," + - "\"role\":\"admin\"," + - "\"status\":\"active\"" + - "}"; - - JsonObject jsonObj = JsonObject.readFrom(collaborationJson); - - // When - BoxUser user = new BoxUser(jsonObj); - - // Then - Assert.assertEquals(expectedLogin, user.getLogin()); - Assert.assertEquals(expectedLanguage, user.getLanguage()); - Assert.assertEquals(expectedTimezone, user.getTimezone()); - Assert.assertEquals(expectedSpaceAmount, user.getSpaceAmount()); - Assert.assertEquals(expectedSpaceUsed, user.getSpaceUsed()); - Assert.assertEquals(expectedMaxUploadSize, user.getMaxUploadSize()); - Assert.assertEquals(expectedTitle, user.getJobTitle()); - Assert.assertEquals(expectedPhone, user.getPhone()); - Assert.assertEquals(expectedAddress, user.getAddress()); - Assert.assertEquals(expectedAvatarURL, user.getAvatarURL()); - Assert.assertArrayEquals(expectedTrackingCode.toArray(), user.getTrackingCodes().toArray()); - Assert.assertEquals(expectedCanSeeMaangedUsers, user.getCanSeeManagedUsers()); - Assert.assertEquals(expectedIsSyncEnabled, user.getIsSyncEnabled()); - Assert.assertEquals(expectedIsExemptFromLoginVerification, user.getIsExemptFromLoginVerification()); - Assert.assertEquals(expectedIsExemptFromDeviceLimits, user.getIsExemptFromDeviceLimits()); - Assert.assertEquals(expectedEnterprise, user.getEnterprise()); - Assert.assertEquals(expectedHostname, user.getHostname()); - Assert.assertArrayEquals(expectedTags.toArray(), user.getMyTags().toArray()); - Assert.assertEquals(expectedRole, user.getRole()); - Assert.assertEquals(expectedStatus, user.getStatus()); - } - - @Test - public void testCreateFromId() { - // given - String expectedId = "5"; - String expectedType = BoxUser.TYPE; - - // when - BoxUser user = BoxUser.createFromId(expectedId); - String id = user.getId(); - String type = user.getType(); - - // then - Assert.assertEquals(expectedId, id); - Assert.assertEquals(expectedType, type); - } -} diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxCollaborationRequestTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxCollaborationRequestTest.java deleted file mode 100644 index a87d440e..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxCollaborationRequestTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.box.androidsdk.content.requests; - -import com.box.androidsdk.content.BoxApiCollaboration; -import com.box.androidsdk.content.BoxException; -import com.box.androidsdk.content.models.BoxCollaboration; -import com.box.androidsdk.content.models.BoxFile; -import com.box.androidsdk.content.models.BoxUser; -import com.box.androidsdk.content.testUtil.PowerMock; - -import junit.framework.Assert; - -import org.junit.Test; - -import java.io.UnsupportedEncodingException; -import java.lang.reflect.InvocationTargetException; -import java.text.ParseException; - -public class BoxCollaborationRequestTest extends PowerMock { - - @Test - public void testAddCollaborationRequestTest() throws NoSuchMethodException, BoxException, InvocationTargetException, IllegalAccessException, UnsupportedEncodingException, ParseException { - - String expected = "{\"item\":{\"id\":\"testFileId\",\"type\":\"file\"},\"accessible_by\":{\"id\":\"testUserId\",\"type\":\"user\"},\"role\":\"editor\"}"; - BoxApiCollaboration apiCollaboration = new BoxApiCollaboration(null); - BoxUser user = BoxUser.createFromId("testUserId"); - BoxRequestsShare.AddCollaboration collabRequest = apiCollaboration.getAddRequest(BoxFile.createFromId("testFileId"), BoxCollaboration.Role.EDITOR, user); - String actual = collabRequest.getStringBody(); - Assert.assertEquals(expected, actual); - } -} \ No newline at end of file diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxDownloadRequestTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxDownloadRequestTest.java deleted file mode 100644 index ba132b21..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxDownloadRequestTest.java +++ /dev/null @@ -1,221 +0,0 @@ -package com.box.androidsdk.content.requests; - -import android.content.Context; - -import com.box.androidsdk.content.BoxApiFile; -import com.box.androidsdk.content.BoxException; -import com.box.androidsdk.content.listeners.DownloadStartListener; -import com.box.androidsdk.content.listeners.ProgressListener; -import com.box.androidsdk.content.models.BoxDownload; -import com.box.androidsdk.content.testUtil.PowerMock; -import com.box.androidsdk.content.testUtil.SessionUtil; -import com.box.androidsdk.content.utils.SdkUtils; - -import junit.framework.Assert; - -import org.junit.Test; -import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Date; - -/** - * Tests for download requests - */ - -@PrepareForTest({ BoxHttpResponse.class, BoxRequestDownload.class, BoxHttpRequest.class}) -public class BoxDownloadRequestTest extends PowerMock { - @Mock - Context mMockContext; - private long mBytesRead; - final static String DOWNLOAD_CONTENT = "testFileContent"; - final static String FILE_ID = "5000948880"; - - - - @Test - public void testDownloadFileRequest() throws Exception { - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - - //Byte stream to capture the outputstream to the server - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024); - final Date now = new Date(System.currentTimeMillis()); - final int contentLength = DOWNLOAD_CONTENT.getBytes().length; - - //Mock httpurlconnection for downloads - URL u = PowerMockito.mock(URL.class); - PowerMockito.whenNew(URL.class).withAnyArguments().thenReturn(u); - HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class); - PowerMockito.when(u.openConnection()).thenReturn(huc); - PowerMockito.when(huc.getOutputStream()).thenReturn(outputStream); - PowerMockito.when(huc.getContentType()).thenReturn(BoxRequest.ContentTypes.JSON.toString()); - PowerMockito.when(huc.getResponseCode()).thenReturn(200); - PowerMockito.when(huc.getHeaderField("Content-Length")).thenReturn(String.valueOf(contentLength)); - - //Mock Response to use sample json - BoxHttpResponse response = new BoxHttpResponse(huc); - PowerMockito.when(response.getContentLength()).thenReturn(contentLength); - PowerMockito.when(response.getBody()).thenReturn(new ByteArrayInputStream(DOWNLOAD_CONTENT.getBytes())); - PowerMockito.whenNew(BoxHttpResponse.class).withAnyArguments().thenReturn(response); - - - OutputStream outputStream1 = new ByteArrayOutputStream(contentLength); - BoxRequestsFile.DownloadFile downloadFileRequest = fileApi.getDownloadRequest(outputStream1, FILE_ID); - - Assert.assertEquals(FILE_ID, downloadFileRequest.getId()); - downloadFileRequest.setProgressListener(new ProgressListener() { - @Override - public void onProgressChanged(long numBytes, long totalBytes) { - mBytesRead += numBytes; - } - }); - - downloadFileRequest.setDownloadStartListener(new DownloadStartListener() { - @Override - public void onStart(BoxDownload downloadInfo) { - Assert.assertNotNull(downloadInfo); - Assert.assertEquals(contentLength, downloadInfo.getContentLength().longValue()); - } - }); - - ByteArrayInputStream inputStream = new ByteArrayInputStream(DOWNLOAD_CONTENT.getBytes()); - downloadFileRequest.setSha1(SdkUtils.sha1(inputStream)); - - //Test send - downloadFileRequest.send(); - Assert.assertEquals(DOWNLOAD_CONTENT.getBytes().length, mBytesRead); - } - - @Test - public void testDownloadFileRequestGetters() throws IOException { - - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFile.DownloadFile downloadFileRequest = fileApi.getDownloadRequest(new ByteArrayOutputStream(), FILE_ID); - - - //Test getters and setters - BoxRequestDownload.DownloadRequestHandler handler = new BoxRequestDownload.DownloadRequestHandler(downloadFileRequest); - downloadFileRequest.setRequestHandler(handler); - Assert.assertEquals(handler, downloadFileRequest.getRequestHandler()); - - Assert.assertEquals(FILE_ID, downloadFileRequest.getId()); - - final long rangeStart = 0; - final long rangeEnd = 100; - downloadFileRequest.setRange(rangeStart, rangeEnd); - Assert.assertEquals(rangeStart, downloadFileRequest.getRangeStart()); - Assert.assertEquals(rangeEnd, downloadFileRequest.getRangeEnd()); - - String version = "version"; - downloadFileRequest.setVersion(version); - Assert.assertEquals(version, downloadFileRequest.getVersion()); - - } - - - @Test - public void testDownloadThumbnailRequest() throws Exception { - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - - //Byte stream to capture the outputstream to the server - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024); - final Date now = new Date(System.currentTimeMillis()); - final int contentLength = DOWNLOAD_CONTENT.getBytes().length; - - //Mock httpurlconnection for downloads - URL u = PowerMockito.mock(URL.class); - PowerMockito.whenNew(URL.class).withAnyArguments().thenReturn(u); - HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class); - PowerMockito.when(u.openConnection()).thenReturn(huc); - PowerMockito.when(huc.getOutputStream()).thenReturn(outputStream); - PowerMockito.when(huc.getContentType()).thenReturn(BoxRequest.ContentTypes.JSON.toString()); - PowerMockito.when(huc.getResponseCode()).thenReturn(200); - PowerMockito.when(huc.getHeaderField("Content-Length")).thenReturn(String.valueOf(contentLength)); - - //Mock Response to use sample json - BoxHttpResponse response = new BoxHttpResponse(huc); - PowerMockito.when(response.getContentLength()).thenReturn(contentLength); - PowerMockito.when(response.getBody()).thenReturn(new ByteArrayInputStream(DOWNLOAD_CONTENT.getBytes())); - PowerMockito.whenNew(BoxHttpResponse.class).withAnyArguments().thenReturn(response); - - - OutputStream outputStream1 = new ByteArrayOutputStream(contentLength); - BoxRequestsFile.DownloadThumbnail downloadThumbnailRequest = fileApi.getDownloadThumbnailRequest(outputStream1, FILE_ID); - - Assert.assertEquals(FILE_ID, downloadThumbnailRequest.getId()); - downloadThumbnailRequest.setProgressListener(new ProgressListener() { - @Override - public void onProgressChanged(long numBytes, long totalBytes) { - mBytesRead += numBytes; - } - }); - - downloadThumbnailRequest.setDownloadStartListener(new DownloadStartListener() { - @Override - public void onStart(BoxDownload downloadInfo) { - Assert.assertNotNull(downloadInfo); - Assert.assertEquals(contentLength, downloadInfo.getContentLength().longValue()); - } - }); - - //Test send - downloadThumbnailRequest.send(); - Assert.assertEquals(DOWNLOAD_CONTENT.getBytes().length, mBytesRead); - } - - @Test - public void testCorruptedDownloadFileSha1Checks() throws Exception { - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - - //Byte stream to capture the outputstream to the server - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024); - final Date now = new Date(System.currentTimeMillis()); - final int contentLength = DOWNLOAD_CONTENT.getBytes().length; - - //Mock httpurlconnection for downloads - URL u = PowerMockito.mock(URL.class); - PowerMockito.whenNew(URL.class).withAnyArguments().thenReturn(u); - HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class); - PowerMockito.when(u.openConnection()).thenReturn(huc); - PowerMockito.when(huc.getOutputStream()).thenReturn(outputStream); - PowerMockito.when(huc.getContentType()).thenReturn(BoxRequest.ContentTypes.JSON.toString()); - PowerMockito.when(huc.getResponseCode()).thenReturn(200); - PowerMockito.when(huc.getHeaderField("Content-Length")).thenReturn(String.valueOf(contentLength)); - - //Mock Response to use sample json - BoxHttpResponse response = new BoxHttpResponse(huc); - PowerMockito.when(response.getContentLength()).thenReturn(contentLength); - PowerMockito.when(response.getBody()).thenReturn(new ByteArrayInputStream(DOWNLOAD_CONTENT.getBytes())); - PowerMockito.whenNew(BoxHttpResponse.class).withAnyArguments().thenReturn(response); - - - OutputStream outputStream1 = new ByteArrayOutputStream(contentLength); - BoxRequestsFile.DownloadFile downloadFileRequest = fileApi.getDownloadRequest(outputStream1, FILE_ID); - - downloadFileRequest.setProgressListener(new ProgressListener() { - @Override - public void onProgressChanged(long numBytes, long totalBytes) { - mBytesRead += numBytes; - } - }); - - downloadFileRequest.setSha1("corruptSha1"); - - try { - - //Test send with wrong sha1 - downloadFileRequest.send(); - Assert.fail("No exception thrown with incorrect digest"); - } catch (BoxException e) { - Assert.assertEquals(BoxException.ErrorType.CORRUPTED_FILE_TRANSFER, e.getErrorType()); - } - - } -} diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxFileRequestTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxFileRequestTest.java deleted file mode 100644 index 77594383..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxFileRequestTest.java +++ /dev/null @@ -1,204 +0,0 @@ -package com.box.androidsdk.content.requests; - -import android.content.Context; - -import com.box.androidsdk.content.BoxApiFile; -import com.box.androidsdk.content.models.BoxComment; -import com.box.androidsdk.content.models.BoxExpiringEmbedLinkFile; -import com.box.androidsdk.content.models.BoxFile; -import com.box.androidsdk.content.models.BoxFileVersion; -import com.box.androidsdk.content.models.BoxIteratorCollaborations; -import com.box.androidsdk.content.models.BoxIteratorComments; -import com.box.androidsdk.content.models.BoxIteratorFileVersions; -import com.box.androidsdk.content.models.BoxSharedLink; -import com.box.androidsdk.content.testUtil.PowerMock; -import com.box.androidsdk.content.testUtil.SessionUtil; -import com.box.androidsdk.content.utils.BoxDateFormat; -import com.eclipsesource.json.JsonObject; - -import junit.framework.Assert; - -import org.junit.Test; -import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.TimeZone; - - -@PrepareForTest({ BoxHttpResponse.class, BoxHttpRequest.class, BoxRequestsFile.GetFileInfo.class, BoxRequestsFile.CopyFile.class, - BoxRequestsFile.class, BoxRequestUpdateSharedItem.class}) -public class BoxFileRequestTest extends PowerMock { - - private final static String FILE_ID = "5000948880"; - private static final String PARENT_FOLDER_ID = "11446498" ; - final String SAMPLE_FILE_JSON = "{ \"type\": \"file\", \"id\": \"5000948880\", \"file_version\": { \"type\": \"file_version\", \"id\": \"26261748416\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\" }, \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\", \"description\": \"a picture of tigers\", \"size\": 629644, \"path_collection\": { \"total_count\": 2, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" } ] }, \"created_at\": \"2012-12-12T10:55:30-08:00\", \"modified_at\": \"2012-12-12T11:04:26-08:00\", \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/rh935iit6ewrmw0unyul\", \"download_url\": \"https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg\", \"vanity_url\": null, \"is_password_enabled\": false, \"unshared_at\": null, \"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", \"permissions\": { \"can_download\": true, \"can_preview\": true } }, \"parent\": { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" }, \"item_status\": \"active\" }"; - - - @Mock - Context mMockContext; - - @Test - public void testFileUpdateRequest() throws Exception { - String expectedRequestBody = "{\"name\":\"NewName\",\"description\":\"NewDescription\",\"parent\":{\"id\":\"0\",\"type\":\"folder\"},\"shared_link\":{\"access\":\"collaborators\",\"unshared_at\":\"2015-01-01T00:00:00-08:00\",\"permissions\":{\"can_download\":true}},\"tags\":[\"tag1\",\"tag2\"]}"; - String expectedRequestUrl = "https://api.box.com/2.0/files/" + FILE_ID; - TimeZone.setDefault(TimeZone.getTimeZone("GMT-8")); - Date unshared = BoxDateFormat.parse("2015-01-01T00:00:00-08:00"); - List tags = new ArrayList(); - tags.add("tag1"); - tags.add("tag2"); - - BoxApiFile fileApi = new BoxApiFile(null); - BoxRequestsFile.UpdatedSharedFile updateReq = fileApi.getUpdateRequest(FILE_ID) - .setName("NewName") - .setDescription("NewDescription") - .setParentId("0") - .updateSharedLink() - .setAccess(BoxSharedLink - .Access.COLLABORATORS) - .setUnsharedAt(unshared) - .setCanDownload(true) - .setTags(tags); - - String actual = updateReq.getStringBody(); - Assert.assertEquals(expectedRequestUrl, updateReq.mRequestUrlString); - Assert.assertEquals(expectedRequestBody, actual); - } - - - @Test - public void testFileInfoRequest() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/files/" + FILE_ID; - - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFile.GetFileInfo fileInfoRequest = fileApi.getInfoRequest(FILE_ID); - fileInfoRequest.setFields(BoxFile.ALL_FIELDS); - - mockSuccessResponseWithJson(SAMPLE_FILE_JSON); - BoxFile boxFile = fileInfoRequest.send(); - - Assert.assertEquals(expectedRequestUrl, fileInfoRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(SAMPLE_FILE_JSON), boxFile.toJsonObject()); - - } - - @Test - public void testFileCopyRequest() throws Exception { - { - final String expectedRequestUrl = "https://api.box.com/2.0/files/" + FILE_ID + "/copy"; - - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFile.CopyFile copyFile = fileApi.getCopyRequest(FILE_ID, PARENT_FOLDER_ID); - mockSuccessResponseWithJson(SAMPLE_FILE_JSON); - BoxFile boxFile = copyFile.send(); - - Assert.assertEquals(expectedRequestUrl, copyFile.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(SAMPLE_FILE_JSON), boxFile.toJsonObject()); - } - } - - @Test - public void testFileCollaborationsRequest() throws Exception { - { - final String expectedRequestUrl = "https://api.box.com/2.0/files/" + FILE_ID + "/collaborations"; - final String sampleCollaborationsJson = "{ \"next_marker\": \"ZmlQZS0xLTE%3D\", \"entries\": [ { \"type\": \"collaboration\", \"id\": \"14176246\", \"created_by\": { \"type\": \"user\", \"id\": \"4276790\", \"name\": \"David Lee\", \"login\": \"david@box.com\" }, \"created_at\": \"2011-11-29T12:56:35-08:00\", \"modified_at\": \"2012-09-11T15:12:32-07:00\", \"expires_at\": null, \"status\": \"accepted\", \"accessible_by\": { \"type\": \"user\", \"id\": \"755492\", \"name\": \"Simon Tan\", \"login\": \"simon@box.net\" }, \"role\": \"editor\", \"acknowledged_at\": \"2011-11-29T12:59:40-08:00\", \"item\": null } ] }"; - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFile.GetCollaborations getCollaborations = fileApi.getCollaborationsRequest(FILE_ID); - mockSuccessResponseWithJson(sampleCollaborationsJson); - BoxIteratorCollaborations boxCollaborations = getCollaborations.send(); - - Assert.assertEquals(expectedRequestUrl, getCollaborations.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(sampleCollaborationsJson), boxCollaborations.toJsonObject()); - } - } - @Test - public void testFileCommentsRequest() throws Exception { - { - final String expectedRequestUrl = "https://api.box.com/2.0/files/" + FILE_ID + "/comments"; - final String sampleCommentsJson = "{ \"total_count\": 1, \"entries\": [ { \"type\": \"comment\", \"id\": \"191969\", \"is_reply_comment\": false, \"message\": \"These tigers are cool!\", \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"created_at\": \"2012-12-12T11:25:01-08:00\", \"item\": { \"id\": \"5000948880\", \"type\": \"file\" }, \"modified_at\": \"2012-12-12T11:25:01-08:00\" } ] }"; - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFile.GetFileComments commentsRequest = fileApi.getCommentsRequest(FILE_ID); - mockSuccessResponseWithJson(sampleCommentsJson); - BoxIteratorComments boxComments = commentsRequest.send(); - - Assert.assertEquals(expectedRequestUrl, commentsRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(sampleCommentsJson), boxComments.toJsonObject()); - } - } - - @Test - public void testFileVersionsRequest() throws Exception { - { - final String expectedRequestUrl = "https://api.box.com/2.0/files/" + FILE_ID + "/versions"; - final String sampleVersionsJson = "{ \"total_count\": 1, \"entries\": [ { \"type\": \"file_version\", \"id\": \"672259576\", \"sha1\": \"359c6c1ed98081b9a69eb3513b9deced59c957f9\", \"name\": \"Dragons.js\", \"size\": 92556, \"created_at\": \"2012-08-20T10:20:30-07:00\", \"modified_at\": \"2012-11-28T13:14:58-08:00\", \"modified_by\": { \"type\": \"user\", \"id\": \"183732129\", \"name\": \"sean rose\", \"login\": \"sean+apitest@box.com\" } } ] }"; - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFile.GetFileVersions versionsRequest = fileApi.getVersionsRequest(FILE_ID); - mockSuccessResponseWithJson(sampleVersionsJson); - BoxIteratorFileVersions boxComments = versionsRequest.send(); - - Assert.assertEquals(expectedRequestUrl, versionsRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(sampleVersionsJson), boxComments.toJsonObject()); - } - } - @Test - public void testAddCommentRequest() throws Exception { - { - final String expectedRequestUrl = "https://api.box.com/2.0/comments"; - final String sampleCommentsJson = "{ \"type\": \"comment\", \"id\": \"191969\", \"is_reply_comment\": false, \"message\": \"These tigers are cool!\", \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"created_at\": \"2012-12-12T11:25:01-08:00\", \"item\": { \"id\": \"5000948880\", \"type\": \"file\" }, \"modified_at\": \"2012-12-12T11:25:01-08:00\" }"; - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFile.AddCommentToFile commentsRequest = fileApi.getAddCommentRequest(FILE_ID, "msg"); - mockSuccessResponseWithJson(sampleCommentsJson); - BoxComment boxComment = commentsRequest.send(); - - Assert.assertEquals(expectedRequestUrl, commentsRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(sampleCommentsJson), boxComment.toJsonObject()); - } - } - - @Test - public void testTrashFileRequest() throws Exception { - { - final String expectedRequestUrl = "https://api.box.com/2.0/files/" + FILE_ID + "/trash"; - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFile.GetTrashedFile trashedFileRequest = fileApi.getTrashedFileRequest(FILE_ID); - mockSuccessResponseWithJson(SAMPLE_FILE_JSON); - BoxFile boxFile = trashedFileRequest.send(); - - Assert.assertEquals(expectedRequestUrl, trashedFileRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(SAMPLE_FILE_JSON), boxFile.toJsonObject()); - } - } - - @Test - public void testPromoteFileVersionRequest() throws Exception { - { - final String expectedRequestUrl = "https://api.box.com/2.0/files/" + FILE_ID + "/versions/current"; - final String fileVersionSampleJson = "{ \"type\": \"file_version\", \"id\": \"871399\", \"sha1\": \"12039d6dd9a7e6eefc78846802e\", \"name\": \"Stark Family Lineage.doc\", \"size\": 11, \"created_at\": \"2013-11-20T13:20:50-08:00\", \"modified_at\": \"2013-11-20T13:26:48-08:00\", \"modified_by\": { \"type\": \"user\", \"id\": \"13711334\", \"name\": \"Eddard Stark\", \"login\": \"ned@winterfell.com\" } }"; - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFile.PromoteFileVersion promoteVersionRequest = fileApi.getPromoteVersionRequest(FILE_ID, "FILE_VERSION_ID"); - mockSuccessResponseWithJson(fileVersionSampleJson); - BoxFileVersion boxFileVersion = promoteVersionRequest.send(); - - Assert.assertEquals(expectedRequestUrl, promoteVersionRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(fileVersionSampleJson), boxFileVersion.toJsonObject()); - } - } - - @Test - public void testEmbedLinkRequest() throws Exception { - { - final String expectedRequestUrl = "https://api.box.com/2.0/files/" + FILE_ID; - final String embedLinkJson = "{ \"type\": \"file\", \"id\": \"34122832467\", \"etag\": \"1\", \"expiring_embed_link\": { \"url\": \"https://app.box.com/preview/expiring_embed/gvoct6FE!Qz2rDeyxCiHsYpvlnR7JJ0SCfFM2M4YiX9cIwrSo4LOYQgxyP3rzoYuMmXg96mTAidqjPuRH7HFXMWgXEEm5LTi1EDlfBocS-iRfHpc5ZeYrAZpA5B8C0Obzkr4bUoF6wGq8BZ1noN_txyZUU1nLDNuL_u0rsImWhPAZlvgt7662F9lZSQ8nw6zKaRWGyqmj06PnxewCx0EQD3padm6VYkfHE2N20gb5rw1D0a7aaRJZzEijb2ICLItqfMlZ5vBe7zGdEn3agDzZP7JlID3FYdPTITsegB10gKLgSp_AJJ9QAfDv8mzi0bGv1ZmAU1FoVLpGC0XI0UKy3N795rZBtjLlTNcuxapbHkUCoKcgdfmHEn5NRQ3tmw7hiBfnX8o-Au34ttW9ntPspdAQHL6xPzQC4OutWZDozsA5P9sGlI-sC3VC2-WXsbXSedemubVd5vWzpVZtKRlb0gpuXsnDPXnMxSH7_jT4KSLhC8b5kEMPNo33FjEJl5pwS_o_6K0awUdRpEQIxM9CC3pBUZK5ooAc5X5zxo_2FBr1xq1p_kSbt4TVnNeohiLIu38TQysSb7CMR7JRhDDZhMMwAUc0wdSszELgL053lJlPeoiaLA49rAGP_B3BVuwFAFEl696w7UMx5NKu1mA0IOn9pDebzbhTl5HuUvBAHROc1Ocjb28Svyotik1IkPIw_1R33ZyAMvEFyzIygqBj8WedQeSK38iXvF2UXvkAf9kevOdnpwsKYiJtcxeJhFm7LUVKDTufuzuGRw-T7cPtbg\" } }"; - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFile.GetEmbedLinkFileInfo embedLinkRequest = fileApi.getEmbedLinkRequest(FILE_ID); - mockSuccessResponseWithJson(embedLinkJson); - BoxExpiringEmbedLinkFile embedLinkFile = embedLinkRequest.send(); - Assert.assertEquals(expectedRequestUrl, embedLinkRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(embedLinkJson).get(BoxExpiringEmbedLinkFile.FIELD_EMBED_LINK), embedLinkFile.toJsonObject().get(BoxExpiringEmbedLinkFile.FIELD_EMBED_LINK)); - } - } - - -} \ No newline at end of file diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxFolderRequestTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxFolderRequestTest.java deleted file mode 100644 index 0d01544e..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxFolderRequestTest.java +++ /dev/null @@ -1,212 +0,0 @@ -package com.box.androidsdk.content.requests; - -import android.content.Context; - -import com.box.androidsdk.content.BoxApiFolder; -import com.box.androidsdk.content.BoxException; -import com.box.androidsdk.content.models.BoxFolder; -import com.box.androidsdk.content.models.BoxIteratorCollaborations; -import com.box.androidsdk.content.models.BoxIteratorItems; -import com.box.androidsdk.content.models.BoxSharedLink; -import com.box.androidsdk.content.models.BoxUploadEmail; -import com.box.androidsdk.content.testUtil.PowerMock; -import com.box.androidsdk.content.testUtil.SessionUtil; -import com.box.androidsdk.content.utils.BoxDateFormat; -import com.eclipsesource.json.JsonObject; - -import junit.framework.Assert; - -import org.junit.Test; -import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; - -import java.io.UnsupportedEncodingException; -import java.lang.reflect.InvocationTargetException; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.TimeZone; - -@PrepareForTest({ BoxHttpResponse.class, BoxHttpRequest.class, BoxRequest.class, BoxRequestsFolder.class}) -public class BoxFolderRequestTest extends PowerMock { - - private final static String FOLDER_ID = "11446498"; - final String SAMPLE_FOLDER_JSON = "{ \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\", \"created_at\": \"2012-12-12T10:53:43-08:00\", \"modified_at\": \"2012-12-12T11:15:04-08:00\", \"description\": \"Some pictures I took\", \"size\": 629644, \"path_collection\": { \"total_count\": 1, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" } ] }, \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/vspke7y05sb214wjokpk\", \"download_url\": null, \"vanity_url\": null, \"is_password_enabled\": false, \"unshared_at\": null, \"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", \"permissions\": { \"can_download\": true, \"can_preview\": true } }, \"folder_upload_email\": { \"access\": \"open\", \"email\": \"upload.Picture.k13sdz1@u.box.com\" }, \"parent\": { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, \"item_status\": \"active\", \"item_collection\": { \"total_count\": 1, \"entries\": [ { \"type\": \"file\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\" } ], \"offset\": 0, \"limit\": 100 } }"; - - @Mock - Context mMockContext; - - @Test - public void testFolderUpdateRequest() throws NoSuchMethodException, BoxException, InvocationTargetException, IllegalAccessException, UnsupportedEncodingException, ParseException { - String expected = "{\"name\":\"NewName\",\"description\":\"NewDescription\",\"parent\":{\"id\":\"0\",\"type\":\"folder\"},\"folder_upload_email\":{\"access\":\"open\"},\"owned_by\":{\"id\":\"1234\",\"type\":\"user\"},\"sync_state\":\"partially_synced\",\"tags\":[\"tag1\",\"tag2\"]," + - "\"shared_link\":{\"access\":\"collaborators\",\"unshared_at\":\"2015-01-01T00:00:00-08:00\",\"permissions\":{\"can_download\":true}}}"; - - TimeZone.setDefault(TimeZone.getTimeZone("GMT-8")); - Date unshared = BoxDateFormat.parse("2015-01-01T00:00:00-08:00"); - List tags = new ArrayList(); - tags.add("tag1"); - tags.add("tag2"); - - BoxApiFolder folderApi = new BoxApiFolder(null); - BoxRequestsFolder.UpdateSharedFolder updateReq = folderApi.getUpdateRequest("1") - .setName("NewName") - .setDescription("NewDescription") - .setParentId("0") - .setFolderUploadEmailAccess(BoxUploadEmail.Access.OPEN) - .setOwnedById("1234") - .setSyncState(BoxFolder.SyncState.PARTIALLY_SYNCED) - .setTags(tags) - .updateSharedLink() - .setAccess(BoxSharedLink.Access.COLLABORATORS) - .setUnsharedAt(unshared) - .setCanDownload(true); - - String actual = updateReq.getStringBody(); - Assert.assertEquals(expected, actual); - } - - @Test - public void testFolderInfoRequest() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/folders/" + FOLDER_ID; - - BoxApiFolder folderApi = new BoxApiFolder(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFolder.GetFolderInfo folderInfo = folderApi.getInfoRequest(FOLDER_ID); - - mockSuccessResponseWithJson(SAMPLE_FOLDER_JSON); - BoxFolder boxFolder = folderInfo.send(); - - Assert.assertEquals(expectedRequestUrl, folderInfo.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(SAMPLE_FOLDER_JSON), boxFolder.toJsonObject()); - - } - - @Test - public void testFolderItemsRequest() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/folders/" + FOLDER_ID +"/items"; - final String itemsIteratorSampleJson = "{ \"total_count\": 24, \"entries\": [ { \"type\": \"folder\", \"id\": \"192429928\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Stephen Curry Three Pointers\" }, { \"type\": \"file\", \"id\": \"818853862\", \"sequence_id\": \"0\", \"etag\": \"0\", \"name\": \"Warriors.jpg\" } ], \"offset\": 0, \"limit\": 2, \"order\": [ { \"by\": \"type\", \"direction\": \"ASC\" }, { \"by\": \"name\", \"direction\": \"ASC\" } ] }"; - - BoxApiFolder folderApi = new BoxApiFolder(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFolder.GetFolderItems itemsRequest = folderApi.getItemsRequest(FOLDER_ID); - itemsRequest.setLimit(2); - itemsRequest.setOffset(0); - - mockSuccessResponseWithJson(itemsIteratorSampleJson); - BoxIteratorItems boxItems = itemsRequest.send(); - - Assert.assertEquals(expectedRequestUrl, itemsRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(itemsIteratorSampleJson), boxItems.toJsonObject()); - - } - - @Test - public void testCreateFolderRequest() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/folders"; - - BoxApiFolder folderApi = new BoxApiFolder(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFolder.CreateFolder folderCreateRequest = folderApi.getCreateRequest("0", "Pictures"); - - mockSuccessResponseWithJson(SAMPLE_FOLDER_JSON); - BoxFolder boxFolder = folderCreateRequest.send(); - - Assert.assertEquals(expectedRequestUrl, folderCreateRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(SAMPLE_FOLDER_JSON), boxFolder.toJsonObject()); - - } - - - @Test - public void testUpdateFolderRequest() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/folders/" + FOLDER_ID ; - - BoxApiFolder folderApi = new BoxApiFolder(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFolder.UpdateFolder updateRequest = folderApi.getUpdateRequest(FOLDER_ID); - updateRequest.setName("Pictures"); - - mockSuccessResponseWithJson(SAMPLE_FOLDER_JSON); - BoxFolder boxFolder = updateRequest.send(); - - Assert.assertEquals(expectedRequestUrl, updateRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(SAMPLE_FOLDER_JSON), boxFolder.toJsonObject()); - - } - - @Test - public void testCopyFolderRequest() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/folders/" + FOLDER_ID + "/copy" ; - - BoxApiFolder folderApi = new BoxApiFolder(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFolder.CopyFolder copyRequest = folderApi.getCopyRequest( FOLDER_ID, "0"); - - mockSuccessResponseWithJson(SAMPLE_FOLDER_JSON); - BoxFolder boxFolder = copyRequest.send(); - - Assert.assertEquals(expectedRequestUrl, copyRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(SAMPLE_FOLDER_JSON), boxFolder.toJsonObject()); - - } - - @Test - public void testFolderCollaborationsRequest() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/folders/" + FOLDER_ID + "/collaborations" ; - final String sampleCollaborationsJson = "{ \"total_count\": 1, \"entries\": [ { \"type\": \"collaboration\", \"id\": \"14176246\", \"created_by\": { \"type\": \"user\", \"id\": \"4276790\", \"name\": \"David Lee\", \"login\": \"david@box.com\" }, \"created_at\": \"2011-11-29T12:56:35-08:00\", \"modified_at\": \"2012-09-11T15:12:32-07:00\", \"expires_at\": null, \"status\": \"accepted\", \"accessible_by\": { \"type\": \"user\", \"id\": \"755492\", \"name\": \"Simon Tan\", \"login\": \"simon@box.net\" }, \"role\": \"editor\", \"acknowledged_at\": \"2011-11-29T12:59:40-08:00\", \"item\": null } ] }"; - BoxApiFolder folderApi = new BoxApiFolder(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFolder.GetCollaborations collaborationsRequest = folderApi.getCollaborationsRequest( FOLDER_ID); - - mockSuccessResponseWithJson(sampleCollaborationsJson); - BoxIteratorCollaborations boxCollaborations = collaborationsRequest.send(); - - Assert.assertEquals(expectedRequestUrl, collaborationsRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(sampleCollaborationsJson), boxCollaborations.toJsonObject()); - - } - - - @Test - public void testGetFolderWithAllItems() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/folders/" + FOLDER_ID ; - BoxApiFolder folderApi = new BoxApiFolder(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFolder.GetFolderWithAllItems getFolderWithAllItems = folderApi.getFolderWithAllItems( FOLDER_ID); - - mockSuccessResponseWithJson(SAMPLE_FOLDER_JSON); - BoxFolder boxFolder = getFolderWithAllItems.send(); - - Assert.assertEquals(expectedRequestUrl, getFolderWithAllItems.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(SAMPLE_FOLDER_JSON), boxFolder.toJsonObject()); - - } - - - @Test - public void testGetTrashedFolder() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/folders/" + FOLDER_ID + "/trash" ; - BoxApiFolder folderApi = new BoxApiFolder(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFolder.GetTrashedFolder getTrashedFolder = folderApi.getTrashedFolderRequest( FOLDER_ID); - - mockSuccessResponseWithJson(SAMPLE_FOLDER_JSON); - BoxFolder boxCollaborations = getTrashedFolder.send(); - - Assert.assertEquals(expectedRequestUrl, getTrashedFolder.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(SAMPLE_FOLDER_JSON), boxCollaborations.toJsonObject()); - - } - - @Test - public void testGetTrashedItems() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/folders/trash/items" ; - final String trashedItemsJson = "{ \"total_count\": 49542, \"entries\": [ { \"type\": \"file\", \"id\": \"2701979016\", \"sequence_id\": \"1\", \"etag\": \"1\", \"sha1\": \"9d976863fc849f6061ecf9736710bd9c2bce488c\", \"name\": \"file Tue Jul 24 145436 2012KWPX5S.csv\" }, { \"type\": \"file\", \"id\": \"2698211586\", \"sequence_id\": \"1\", \"etag\": \"1\", \"sha1\": \"09b0e2e9760caf7448c702db34ea001f356f1197\", \"name\": \"file Tue Jul 24 010055 20129Z6GS3.csv\" } ], \"offset\": 0, \"limit\": 2 }"; - BoxApiFolder folderApi = new BoxApiFolder(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsFolder.GetTrashedItems trashedItemsRequest = folderApi.getTrashedItemsRequest( ); - - mockSuccessResponseWithJson(trashedItemsJson); - BoxIteratorItems boxItems = trashedItemsRequest.send(); - - Assert.assertEquals(expectedRequestUrl, trashedItemsRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(trashedItemsJson), boxItems.toJsonObject()); - - } - - - - -} \ No newline at end of file diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxMetadataRequestTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxMetadataRequestTest.java deleted file mode 100644 index c5cb026e..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxMetadataRequestTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.box.androidsdk.content.requests; - -import com.box.androidsdk.content.BoxApiMetadata; - -import org.junit.Assert; -import org.junit.Test; - -import java.io.UnsupportedEncodingException; -import java.util.LinkedHashMap; - -/** - * Created by ishay on 7/31/15. - */ -public class BoxMetadataRequestTest { - - @Test - public void testAddFileMetadataRequest() throws UnsupportedEncodingException { - String expected = "{\"invoiceNumber\":\"12345\",\"companyName\":\"Boxers\",\"terms\":\"30\"}"; - - LinkedHashMap map = new LinkedHashMap(); - map.put("invoiceNumber", "12345"); - map.put("companyName", "Boxers"); - map.put("terms", "30"); - BoxRequestsMetadata.AddFileMetadata request = (new BoxApiMetadata(null)).getAddFileMetadataRequest("FILE_ID", map, "enterprise", "invoice"); - Assert.assertEquals(expected, request.getStringBody()); - } - - @Test - public void testUpdateFileMetadataRequest() throws UnsupportedEncodingException { - String expected = "[{\"op\":\"test\",\"path\":\"/companyName\",\"value\":\"Boxers\"},{\"op\":\"remove\",\"path\":\"/companyName\"},{\"op\":\"replace\",\"path\":\"/terms\",\"value\":\"60\"},{\"op\":\"add\",\"path\":\"/approved\",\"value\":\"Yes\"}]"; - - BoxRequestsMetadata.UpdateFileMetadata request = (new BoxApiMetadata(null)).getUpdateFileMetadataRequest("FILE_ID", "enterprise", "invoice"); - request.addUpdateTask(BoxRequestsMetadata.UpdateFileMetadata.Operations.TEST, "companyName", "Boxers"); - request.addUpdateTask(BoxRequestsMetadata.UpdateFileMetadata.Operations.REMOVE, "companyName"); - request.addUpdateTask(BoxRequestsMetadata.UpdateFileMetadata.Operations.REPLACE, "terms", "60"); - request.addUpdateTask(BoxRequestsMetadata.UpdateFileMetadata.Operations.ADD, "approved", "Yes"); - Assert.assertEquals(expected, request.getStringBody()); - } - - @Test - public void testAddFolderMetadataRequest() throws UnsupportedEncodingException { - String expected = "{\"invoiceNumber\":\"12345\",\"companyName\":\"Boxers\",\"terms\":\"30\"}"; - - LinkedHashMap map = new LinkedHashMap(); - map.put("invoiceNumber", "12345"); - map.put("companyName", "Boxers"); - map.put("terms", "30"); - BoxRequestsMetadata.AddItemMetadata request = (new BoxApiMetadata(null)).getAddFolderMetadataRequest("folderId", map, "enterprise", "invoice"); - Assert.assertEquals(expected, request.getStringBody()); - } - - @Test - public void testUpdateFolderMetadataRequest() throws UnsupportedEncodingException { - String expected = "[{\"op\":\"test\",\"path\":\"/companyName\",\"value\":\"Boxers\"},{\"op\":\"remove\",\"path\":\"/companyName\"},{\"op\":\"replace\",\"path\":\"/terms\",\"value\":\"60\"},{\"op\":\"add\",\"path\":\"/approved\",\"value\":\"Yes\"}]"; - - BoxRequestsMetadata.UpdateItemMetadata request = (new BoxApiMetadata(null)).getUpdateFolderMetadataRequest("folderId", "enterprise", "invoice"); - request.addUpdateTask(BoxRequestsMetadata.UpdateFileMetadata.Operations.TEST, "companyName", "Boxers"); - request.addUpdateTask(BoxRequestsMetadata.UpdateFileMetadata.Operations.REMOVE, "companyName"); - request.addUpdateTask(BoxRequestsMetadata.UpdateFileMetadata.Operations.REPLACE, "terms", "60"); - request.addUpdateTask(BoxRequestsMetadata.UpdateFileMetadata.Operations.ADD, "approved", "Yes"); - Assert.assertEquals(expected, request.getStringBody()); - } - -} diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxSearchRequestTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxSearchRequestTest.java deleted file mode 100644 index 84a0899e..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxSearchRequestTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.box.androidsdk.content.requests; - -import android.content.Context; - -import com.box.androidsdk.content.BoxApiSearch; -import com.box.androidsdk.content.models.BoxIteratorItems; -import com.box.androidsdk.content.testUtil.PowerMock; -import com.box.androidsdk.content.testUtil.SessionUtil; -import com.eclipsesource.json.JsonObject; - -import junit.framework.Assert; - -import org.junit.Test; -import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; - -/** - * Tests for search requests - */ - - - -@PrepareForTest({ BoxHttpResponse.class, BoxHttpRequest.class, BoxRequest.class, BoxRequestsSearch.class}) -public class BoxSearchRequestTest extends PowerMock { - - @Mock - Context mMockContext; - - @Test - public void testSearch() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/search"; - final String sampleSearchResultsJson = "{ \"total_count\": 1, \"entries\": [ { \"type\": \"file\", \"id\": \"172245607\", \"sequence_id\": \"1\", \"etag\": \"1\", \"sha1\": \"f89d97c5eea0a68e2cec911s932eca34a52355d2\", \"name\": \"Box for Sales - Empowering Your Mobile Worker White paper 2pg (External).pdf\", \"description\": \"This is old and needs to be updated - but general themes still apply\", \"size\": 408979, \"path_collection\": { \"total_count\": 2, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, { \"type\": \"folder\", \"id\": \"2150506\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Marketing Active Work\" } ] }, \"created_at\": \"2014-05-17T12:59:45-07:00\", \"modified_at\": \"2014-05-17T13:00:20-07:00\", \"trashed_at\": null, \"purged_at\": null, \"content_created_at\": \"2014-05-17T12:58:58-07:00\", \"content_modified_at\": \"2014-05-17T12:58:58-07:00\", \"created_by\": { \"type\": \"user\", \"id\": \"19551097\", \"name\": \"Ted Blosser\", \"login\": \"ted@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"19551097\", \"name\": \"Ted Blosser\", \"login\": \"ted@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"19551097\", \"name\": \"Ted Blosser\", \"login\": \"ted@box.com\" }, \"shared_link\": null, \"parent\": { \"type\": \"folder\", \"id\": \"2150506\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Marketing Active Work\" }, \"item_status\": \"active\" } ], \"limit\": 30, \"offset\": 0 }"; - BoxApiSearch searchApi = new BoxApiSearch(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsSearch.Search searchRequest = searchApi.getSearchRequest("query"); - - mockSuccessResponseWithJson(sampleSearchResultsJson); - BoxIteratorItems searchResults = searchRequest.send(); - - Assert.assertEquals(expectedRequestUrl, searchRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(sampleSearchResultsJson), searchResults.toJsonObject()); - } -} diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxUploadRequestTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxUploadRequestTest.java deleted file mode 100644 index 0773a936..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxUploadRequestTest.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.box.androidsdk.content.requests; - -import android.content.Context; - -import com.box.androidsdk.content.BoxApiFile; -import com.box.androidsdk.content.listeners.ProgressListener; -import com.box.androidsdk.content.testUtil.PowerMock; -import com.box.androidsdk.content.testUtil.SessionUtil; - -import junit.framework.Assert; - -import org.junit.Test; -import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Date; - -/** - * Tests for upload requests - */ - -@PrepareForTest({ BoxHttpResponse.class, BoxRequest.class, BoxRequestMultipart.class}) -public class BoxUploadRequestTest extends PowerMock { - @Mock - Context mMockContext; - private long mBytesRead; - - - @Test - public void testUploadFileRequest() throws Exception { - String requestUrl = "https://upload.box.com/api/2.0/files/content?fields=parent%2Cpath_collection%2Cname%2Csize%2Cmodified_at%2Cdescription%2Curl%2Cshared_link%2Csha1%2Cowned_by%2Ccomment_count%2Ccontent_created_at%2Ccontent_modified_at%2Cmodified_by%2Cpermissions%2Ccollections%2Chas_collaborations%2Chas_collaborations%2Cis_externally_owned%2Callowed_invitee_roles%2Citem_collection"; - String sampleResponseJson = "{ \"total_count\": 1, \"entries\": [ { \"type\": \"file\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\", \"description\": \"a picture of tigers\", \"size\": 629644, \"path_collection\": { \"total_count\": 2, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" } ] }, \"created_at\": \"2012-12-12T10:55:30-08:00\", \"modified_at\": \"2012-12-12T11:04:26-08:00\", \"trashed_at\": null, \"purged_at\": null, \"content_created_at\": \"2013-02-04T16:57:52-08:00\", \"content_modified_at\": \"2013-02-04T16:57:52-08:00\", \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"shared_link\": null, \"parent\": { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" }, \"item_status\": \"active\" } ] }"; - - - - //Byte stream to capture the outputstream to the server - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024); - - //Mock httpurlconnection for uploads - URL u = PowerMockito.mock(URL.class); - PowerMockito.whenNew(URL.class).withAnyArguments().thenReturn(u); - HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class); - PowerMockito.when(u.openConnection()).thenReturn(huc); - PowerMockito.when(huc.getOutputStream()).thenReturn(outputStream); - PowerMockito.when(huc.getContentType()).thenReturn(BoxRequest.ContentTypes.JSON.toString()); - PowerMockito.when(huc.getResponseCode()).thenReturn(200); - - //Mock Response to use sample json - BoxHttpResponse response = new BoxHttpResponse(huc); - PowerMockito.when(response.getBody()).thenReturn(new ByteArrayInputStream(sampleResponseJson.getBytes())); - PowerMockito.whenNew(BoxHttpResponse.class).withAnyArguments().thenReturn(response); - - - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - InputStream inputStream = new ByteArrayInputStream(requestUrl.getBytes()); - final String filename = "filename"; - final String destinationFolderId = "0"; - BoxRequestsFile.UploadFile uploadRequest = fileApi.getUploadRequest(inputStream, filename, destinationFolderId); - - Assert.assertEquals(filename, uploadRequest.getFileName()); - Assert.assertEquals(destinationFolderId, uploadRequest.getDestinationFolderId()); - uploadRequest.setProgressListener(new ProgressListener() { - @Override - public void onProgressChanged(long numBytes, long totalBytes) { - mBytesRead += numBytes; - } - }); - - //Test send - uploadRequest.send(); - Assert.assertTrue(outputStream.toString().contains(requestUrl)); - Assert.assertEquals(requestUrl.getBytes().length, mBytesRead); - } - - @Test - public void testUploadFileRequestGetters() { - - BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); - File file = new File("file"); - BoxRequestsFile.UploadFile uploadRequest = fileApi.getUploadRequest(file, "0"); - - - //Test getters and setters - BoxRequestUpload.UploadRequestHandler handler = new BoxRequestUpload.UploadRequestHandler(uploadRequest); - uploadRequest.setRequestHandler(handler); - Assert.assertEquals(handler, uploadRequest.getRequestHandler()); - - final String filename = "filename"; - uploadRequest.setFileName(filename); - Assert.assertEquals(filename, uploadRequest.getFileName()); - - final String sha1 = "sha1"; - uploadRequest.setSha1(sha1); - Assert.assertEquals(sha1, uploadRequest.getSha1()); - - final long uploadSize = 100; - - uploadRequest.setUploadSize(uploadSize); - Assert.assertEquals(uploadSize, uploadRequest.getUploadSize()); - - Date now = new Date(System.currentTimeMillis()); - uploadRequest.setModifiedDate(now); - uploadRequest.setCreatedDate(now); - Assert.assertEquals(now, uploadRequest.getCreatedDate()); - Assert.assertEquals(now, uploadRequest.getModifiedDate()); - Assert.assertEquals(file, uploadRequest.getFile()); - } -} diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxUserRequestTest.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxUserRequestTest.java deleted file mode 100644 index 1d3956a1..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxUserRequestTest.java +++ /dev/null @@ -1,163 +0,0 @@ -package com.box.androidsdk.content.requests; - -import android.content.Context; - -import com.box.androidsdk.content.BoxApiUser; -import com.box.androidsdk.content.models.BoxIteratorUsers; -import com.box.androidsdk.content.models.BoxUser; -import com.box.androidsdk.content.testUtil.PowerMock; -import com.box.androidsdk.content.testUtil.SessionUtil; -import com.eclipsesource.json.JsonObject; - -import junit.framework.Assert; - -import org.junit.Test; -import org.mockito.Mock; -import org.powermock.core.classloader.annotations.PrepareForTest; - -import java.io.UnsupportedEncodingException; -import java.text.ParseException; - -@PrepareForTest({ BoxHttpResponse.class, BoxHttpRequest.class, BoxRequest.class, BoxRequestsUser.class}) -public class BoxUserRequestTest extends PowerMock { - - private static final String USER_ID = "10543463"; - private static final String SAMPLE_USER_JSON = "{ \"type\": \"user\", \"id\": \"10543463\", \"name\": \"Arielle Frey\", \"login\": \"ariellefrey@box.com\", \"created_at\": \"2011-01-07T12:37:09-08:00\", \"modified_at\": \"2014-05-30T10:39:47-07:00\", \"language\": \"en\", \"timezone\": \"America/Los_Angeles\", \"space_amount\": 10737418240, \"space_used\": 558732, \"max_upload_size\": 5368709120, \"status\": \"active\", \"job_title\": \"\", \"phone\": \"\", \"address\": \"\", \"avatar_url\": \"https://app.box.com/api/avatar/deprecated\" }"; - - @Mock - Context mMockContext; - - @Test - public void testCreateEnterpriseUserRequestProperties() throws ParseException { - String login = "tester@gmail.com"; - String name = "tester"; - String address = "4440 El Camino Real"; - String jobTitle = "Tester"; - String phone = "123-456-7890"; - double space = 1000; - String timezone = "Asia/Hong_Kong"; - - BoxApiUser userApi = new BoxApiUser(null); - BoxRequestsUser.CreateEnterpriseUser request = userApi.getCreateEnterpriseUserRequest(login, name) - .setAddress(address) - .setJobTitle(jobTitle) - .setPhone(phone) - .setSpaceAmount(space) - .setRole(BoxUser.Role.COADMIN) - .setStatus(BoxUser.Status.ACTIVE) -// .setTrackingCodes() - .setTimezone(timezone) - .setCanSeeManagedUsers(true) - .setIsExemptFromDeviceLimits(true) - .setIsExemptFromLoginVerification(true) - .setIsSyncEnabled(true); - - Assert.assertEquals(login, request.getLogin()); - Assert.assertEquals(name, request.getName()); - Assert.assertEquals(address, request.getAddress()); - Assert.assertEquals(jobTitle, request.getJobTitle()); - Assert.assertEquals(phone, request.getPhone()); - Assert.assertEquals(space, request.getSpaceAmount()); - Assert.assertEquals(timezone, request.getTimezone()); - Assert.assertEquals(BoxUser.Status.ACTIVE, request.getStatus()); - Assert.assertEquals(BoxUser.Role.COADMIN, request.getRole()); - Assert.assertTrue(request.getCanSeeManagedUsers()); - Assert.assertTrue(request.getIsExemptFromDeviceLimits()); - Assert.assertTrue(request.getIsExemptFromLoginVerification()); - Assert.assertTrue(request.getCanSeeManagedUsers()); - Assert.assertTrue(request.getIsSyncEnabled()); - } - - @Test - public void testCreateEnterpriseUserRequest() throws UnsupportedEncodingException { - String expected = "{\"login\":\"tester@gmail.com\",\"name\":\"tester\",\"address\":\"4440 El Camino Real\",\"job_title\":\"Tester\",\"phone\":\"123-456-7890\",\"space_amount\":\"1000.0\",\"role\":\"coadmin\",\"status\":\"active\",\"timezone\":\"Asia/Hong_Kong\",\"can_see_managed_users\":\"true\",\"is_exempt_from_device_limits\":\"true\",\"is_exempt_from_login_verification\":\"true\",\"is_sync_enabled\":\"true\"}"; - - String login = "tester@gmail.com"; - String name = "tester"; - String address = "4440 El Camino Real"; - String jobTitle = "Tester"; - String phone = "123-456-7890"; - double space = 1000; - String timezone = "Asia/Hong_Kong"; - - BoxApiUser userApi = new BoxApiUser(null); - BoxRequestsUser.CreateEnterpriseUser request = userApi.getCreateEnterpriseUserRequest(login, name) - .setAddress(address) - .setJobTitle(jobTitle) - .setPhone(phone) - .setSpaceAmount(space) - .setRole(BoxUser.Role.COADMIN) - .setStatus(BoxUser.Status.ACTIVE) -// .setTrackingCodes() - .setTimezone(timezone) - .setCanSeeManagedUsers(true) - .setIsExemptFromDeviceLimits(true) - .setIsExemptFromLoginVerification(true) - .setIsSyncEnabled(true); - - String json = request.getStringBody(); - Assert.assertEquals(expected, json); - } - - @Test - public void testUserInfoRequest() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/users/" + USER_ID; - - BoxApiUser userApi = new BoxApiUser(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsUser.GetUserInfo userInfoRequest = userApi.getUserInfoRequest(USER_ID); - - mockSuccessResponseWithJson(SAMPLE_USER_JSON); - BoxUser boxUser = userInfoRequest.send(); - - Assert.assertEquals(expectedRequestUrl, userInfoRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(SAMPLE_USER_JSON), boxUser.toJsonObject()); - - } - - @Test - public void testCurrentUserInfoRequest() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/users/me"; - - BoxApiUser userApi = new BoxApiUser(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsUser.GetUserInfo userInfoRequest = userApi.getCurrentUserInfoRequest(); - - mockSuccessResponseWithJson(SAMPLE_USER_JSON); - BoxUser boxUser = userInfoRequest.send(); - - Assert.assertEquals(expectedRequestUrl, userInfoRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(SAMPLE_USER_JSON), boxUser.toJsonObject()); - - } - - @Test - public void testMockCreateEnterpriseUserRequest() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/users"; - - BoxApiUser userApi = new BoxApiUser(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsUser.CreateEnterpriseUser userInfoRequest = userApi.getCreateEnterpriseUserRequest("ariellefrey@box.com", "Arielle Frey"); - - mockSuccessResponseWithJson(SAMPLE_USER_JSON); - BoxUser boxUser = userInfoRequest.send(); - - Assert.assertEquals(expectedRequestUrl, userInfoRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(SAMPLE_USER_JSON), boxUser.toJsonObject()); - - } - - @Test - public void testGetEnterpriseUsersRequest() throws Exception { - final String expectedRequestUrl = "https://api.box.com/2.0/users"; - final String enterpriseUsersJson = "{ \"total_count\": 1, \"entries\": [ { \"type\": \"user\", \"id\": \"181216415\", \"name\": \"sean rose\", \"login\": \"sean+awesome@box.com\", \"created_at\": \"2012-05-03T21:39:11-07:00\", \"modified_at\": \"2012-08-23T14:57:48-07:00\", \"language\": \"en\", \"space_amount\": 5368709120, \"space_used\": 52947, \"max_upload_size\": 104857600, \"status\": \"active\", \"job_title\": \"\", \"phone\": \"5555551374\", \"address\": \"10 Cloud Way Los Altos CA\", \"avatar_url\": \"https://app.box.com/api/avatar/large/181216415\" } ] }"; - BoxApiUser userApi = new BoxApiUser(SessionUtil.newMockBoxSession(mMockContext)); - BoxRequestsUser.GetEnterpriseUsers enterpriseUsersRequest = userApi.getEnterpriseUsersRequest(); - - mockSuccessResponseWithJson(enterpriseUsersJson); - BoxIteratorUsers boxUsers = enterpriseUsersRequest.send(); - - Assert.assertEquals(expectedRequestUrl, enterpriseUsersRequest.mRequestUrlString); - Assert.assertEquals(JsonObject.readFrom(enterpriseUsersJson), boxUsers.toJsonObject()); - - } - - -} diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/testUtil/DateUtil.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/testUtil/DateUtil.java deleted file mode 100644 index 2b91b1e4..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/testUtil/DateUtil.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.box.androidsdk.content.testUtil; - - -import org.junit.Assert; - -import java.util.Date; - -public class DateUtil { - public static void assertSameDateSecondPrecision(Date expectedDate, Date date) { - long expectedDateTruncated = expectedDate.getTime() / 1000; - long dateTruncated = date.getTime() / 1000; - Assert.assertEquals(expectedDateTruncated, dateTruncated); - } -} diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/testUtil/PowerMock.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/testUtil/PowerMock.java deleted file mode 100644 index bed72f65..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/testUtil/PowerMock.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.box.androidsdk.content.testUtil; - -import android.text.TextUtils; - -import com.box.androidsdk.content.requests.BoxHttpResponse; -import com.box.androidsdk.content.requests.BoxRequest; - -import org.junit.Before; -import org.junit.runner.RunWith; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.net.HttpURLConnection; -import java.net.URL; - -import static org.mockito.Matchers.any; - -/** - * Created by jholzer on 11/22/17. - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest(TextUtils.class) -public abstract class PowerMock { - - /** - * Method to simplify mocking a 200 response with a sample json body - * @param sampleJson - * @throws Exception - */ - protected static void mockSuccessResponseWithJson(String sampleJson) throws Exception { - //Byte stream to capture the outputstream to the server - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024); - URL u = PowerMockito.mock(URL.class); - PowerMockito.whenNew(URL.class).withAnyArguments().thenReturn(u); - HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class); - PowerMockito.when(u.openConnection()).thenReturn(huc); - PowerMockito.when(huc.getOutputStream()).thenReturn(outputStream); - PowerMockito.when(huc.getContentType()).thenReturn(BoxRequest.ContentTypes.JSON.toString()); - PowerMockito.when(huc.getResponseCode()).thenReturn(200); - - - //Mock Response with sample json - BoxHttpResponse response = new BoxHttpResponse(huc); - PowerMockito.when(response.getBody()).thenReturn(new ByteArrayInputStream(sampleJson.getBytes())); - PowerMockito.whenNew(BoxHttpResponse.class).withAnyArguments().thenReturn(response); - } - - @Before - public void setup() { - PowerMockito.mockStatic(TextUtils.class); - PowerMockito.when(TextUtils.isEmpty(any(CharSequence.class))).thenAnswer(new Answer() { - @Override - public Boolean answer(InvocationOnMock invocation) throws Throwable { - CharSequence a = (CharSequence) invocation.getArguments()[0]; - return !(a != null && a.length() > 0); - } - }); - } -} diff --git a/box-content-sdk/src/test/java/com/box/androidsdk/content/testUtil/SessionUtil.java b/box-content-sdk/src/test/java/com/box/androidsdk/content/testUtil/SessionUtil.java deleted file mode 100644 index e65353e3..00000000 --- a/box-content-sdk/src/test/java/com/box/androidsdk/content/testUtil/SessionUtil.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.box.androidsdk.content.testUtil; - -import android.content.Context; - -import com.box.androidsdk.content.auth.BoxAuthentication; -import com.box.androidsdk.content.models.BoxSession; - -/** - * Utils for mocking the BoxSession - */ - -public class SessionUtil { - public static BoxSession newMockBoxSession(Context context) { - BoxAuthentication.BoxAuthenticationInfo authenticationInfo = new BoxAuthentication.BoxAuthenticationInfo(); - authenticationInfo.setAccessToken("accessTokenMock"); - return new BoxSession(context, authenticationInfo, null); - } -}