diff options
author | Matthias Sohn | 2015-03-04 23:09:15 +0000 |
---|---|---|
committer | Matthias Sohn | 2015-03-05 12:25:42 +0000 |
commit | 0857b455f61a38cd8ec96de9eef6c82c04f8a9a1 (patch) | |
tree | 74371b6740f54933f72d840e96c34f3b5aa04b0a | |
parent | eb83c17e47247e19c41aaba497f4c91d6e2a96c5 (diff) | |
download | egit-github-0857b455f61a38cd8ec96de9eef6c82c04f8a9a1.tar.gz egit-github-0857b455f61a38cd8ec96de9eef6c82c04f8a9a1.tar.xz egit-github-0857b455f61a38cd8ec96de9eef6c82c04f8a9a1.zip |
Prevent invalid CommitStatus.state values
see https://developer.github.com/v3/repos/statuses/
Change-Id: I62f8cbf1e276a3d3da270292153a80028c872b2c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
3 files changed, 25 insertions, 3 deletions
diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitServiceTest.java index 1f4adb5d..1a378ebb 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitServiceTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitServiceTest.java @@ -451,4 +451,20 @@ public class CommitServiceTest { public void createStatusNullStatus() throws IOException { service.createStatus(new RepositoryId("o", "n"), "123", null); } + + /** + * Create status + * + * @throws IOException + */ + @Test(expected = IllegalArgumentException.class) + public void createStatusInvalidState() throws IOException { + RepositoryId repo = new RepositoryId("o", "n"); + CommitStatus status = new CommitStatus(); + status.setState("non-existing-state"); + status.setDescription("description"); + status.setTargetUrl("http://target/url"); + status.setContext("context"); + service.createStatus(repo, "123", status); + } }
\ No newline at end of file diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitStatusTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitStatusTest.java index 9b12b23a..37e39374 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitStatusTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/CommitStatusTest.java @@ -55,7 +55,7 @@ public class CommitStatusTest { assertEquals("con/text", status.setContext("con/text").getContext()); assertEquals("desc", status.setDescription("desc").getDescription()); assertEquals(40, status.setId(40).getId()); - assertEquals("state", status.setState("state").getState()); + assertEquals("success", status.setState("success").getState()); assertEquals("targetUrl", status.setTargetUrl("targetUrl") .getTargetUrl()); assertEquals(new Date(5678), status.setUpdatedAt(new Date(5678)) diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/CommitStatus.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/CommitStatus.java index b6df83e4..e178014d 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/CommitStatus.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/CommitStatus.java @@ -11,6 +11,7 @@ package org.eclipse.egit.github.core; import java.io.Serializable; +import java.text.MessageFormat; import java.util.Date; import org.eclipse.egit.github.core.util.DateUtils; @@ -150,10 +151,15 @@ public class CommitStatus implements Serializable { /** * @param state * @return this status + * throws {@link IllegalArgumentException} if state is invalid */ public CommitStatus setState(final String state) { - this.state = state; - return this; + if (STATE_ERROR.equals(state) || STATE_FAILURE.equals(state) || STATE_PENDING.equals(state) + || STATE_SUCCESS.equals(state)) { + this.state = state; + return this; + } + throw new IllegalArgumentException(MessageFormat.format("Invalid state {0}", state)); } /** |