Skip to content

Commit 92a89a3

Browse files
committed
Merge pull request #53 from gcurtis/master
Add UNKNOWN event type
2 parents 386757e + 64229f9 commit 92a89a3

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/main/java/com/box/sdk/BoxEvent.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,17 @@ void parseJsonMember(JsonObject.Member member) {
5858
this.sourceInfo = BoxResource.parseInfo(this.getAPI(), value.asObject());
5959
break;
6060
case "event_type":
61-
this.type = BoxEvent.Type.valueOf(value.asString());
61+
String stringValue = value.asString();
62+
for (Type t : Type.values()) {
63+
if (t.name().equals(stringValue)) {
64+
this.type = t;
65+
break;
66+
}
67+
}
68+
69+
if (this.type == null) {
70+
this.type = Type.UNKNOWN;
71+
}
6272
break;
6373
default:
6474
break;
@@ -69,6 +79,11 @@ void parseJsonMember(JsonObject.Member member) {
6979
* Enumerates the possible types for an event.
7080
*/
7181
public enum Type {
82+
/**
83+
* The type of the event is unknown.
84+
*/
85+
UNKNOWN,
86+
7287
/**
7388
* An file or folder was created.
7489
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.box.sdk;
2+
3+
import static org.hamcrest.Matchers.is;
4+
import static org.junit.Assert.assertThat;
5+
6+
import org.junit.Test;
7+
import org.junit.experimental.categories.Category;
8+
9+
public class BoxEventTest {
10+
@Test
11+
@Category(UnitTest.class)
12+
public void newBoxEventHandlesUnknownEventType() {
13+
String eventJSON = "{ \"type\": \"event\", \"event_id\": \"f82c3ba03e41f7e8a7608363cc6c0390183c3f83\", "
14+
+ "\"event_type\": \"UNKNOWN_EVENT_TYPE\" }";
15+
BoxEvent event = new BoxEvent(null, eventJSON);
16+
17+
assertThat(event.getType(), is(BoxEvent.Type.UNKNOWN));
18+
}
19+
}

0 commit comments

Comments
 (0)