Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc commit status API fixes #1129

Merged
merged 12 commits into from
Jun 18, 2015
2 changes: 1 addition & 1 deletion src/main/java/com/jcabi/github/Commits.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ Commit create(
* @since 0.23
* @return Status
*/
@NotNull(message = "status is never NULL")
@NotNull(message = "statuses is never NULL")
Statuses statuses(@NotNull(message = "sha can't be NULL") final String ref);
}
2 changes: 1 addition & 1 deletion src/main/java/com/jcabi/github/RtCommits.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public Commit get(
}

@Override
@NotNull(message = "status is never NULL")
@NotNull(message = "statuses is never NULL")
public Statuses statuses(
@NotNull(message = "ref can't be NULL") final String ref
) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/jcabi/github/RtStatuses.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public final Commit commit() {
* @throws IOException In case of any I/O problems
*/
@Override
@NotNull(message = "status is never NULL")
public final Status create(
@NotNull(message = "status can't be NULL") final StatusCreate status
) throws IOException {
Expand Down
75 changes: 1 addition & 74 deletions src/main/java/com/jcabi/github/Statuses.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.jcabi.aspects.Immutable;
import com.jcabi.aspects.Loggable;
import java.io.IOException;
import java.net.URL;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
Expand Down Expand Up @@ -74,6 +73,7 @@ public interface Statuses extends JsonReadable {
* @return The added status
* @see <a href="https://developer.github.com/v3/repos/statuses/#create-a-status">Create a Status</a>
*/
@NotNull(message = "status is never NULL")
Status create(
@NotNull(message = "status creation data can't be NULL")
final StatusCreate status
Expand All @@ -90,79 +90,6 @@ Iterable<Status> list(
@NotNull(message = "ref can't be NULL") final String ref
);

/**
* Smart commit.
*/
@Immutable
@ToString
@Loggable(Loggable.DEBUG)
@EqualsAndHashCode(of = { "statuses", "jsn" })
final class Smart implements Statuses {
/**
* Encapsulated status.
*/
private final transient Statuses statuses;
/**
* SmartJson object for convenient JSON parsing.
*/
private final transient SmartJson jsn;
/**
* Public ctor.
* @param stats Status
*/
public Smart(
@NotNull(message = "cmt can't be NULL")
final Statuses stats
) {
this.statuses = stats;
this.jsn = new SmartJson(this.statuses);
}
/**
* Get its message.
* @return Message of commit
* @throws java.io.IOException If there is any I/O problem
*/
@NotNull(message = "message is never NULL")
public String message() throws IOException {
return this.jsn.text("message");
}
/**
* Get its URL.
* @return URL of comment
* @throws IOException If there is any I/O problem
*/
@NotNull(message = "URL is never NULL")
public URL url() throws IOException {
return new URL(this.jsn.text("url"));
}
@Override
@NotNull(message = "commit is never NULL")
public Commit commit() {
return this.statuses.commit();
}

@Override
public Status create(
@NotNull(message = "status can't be NULL")
final StatusCreate status
) throws IOException {
return this.statuses.create(status);
}

@Override
public Iterable<Status> list(
@NotNull(message = "ref can't be NULL") final String ref
) {
return this.statuses.list(ref);
}

@Override
@NotNull(message = "JSON is never NULL")
public JsonObject json() throws IOException {
return this.statuses.json();
}
}

/**
* Data to use when creating a new GitHub commit status.
*
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/jcabi/github/mock/MkCommits.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ public Commit get(
}

@Override
@NotNull(message = "statuses is never NULL")
public Statuses statuses(
@NotNull(message = "sha can't be NULL") final String sha
@NotNull(message = "sha can't be NULL") final String sha
) {
throw new UnsupportedOperationException("Not implemented");
return new MkStatuses(this.get(sha));
}
}
97 changes: 97 additions & 0 deletions src/main/java/com/jcabi/github/mock/MkStatuses.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* Copyright (c) 2013-2015, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.github.mock;

import com.jcabi.aspects.Immutable;
import com.jcabi.aspects.Loggable;
import com.jcabi.github.Commit;
import com.jcabi.github.Status;
import com.jcabi.github.Statuses;
import java.io.IOException;
import javax.json.JsonObject;
import javax.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;

/**
* Mock of GitHub commit statuses.
* @author Chris Rebert ([email protected])
* @version $Id$
* @since 0.24
* @todo #1129:30min Finish implementing this class (MkStatuses), a mock of
* GitHub's commits statuses (the "Statuses" interface).
*/
@Immutable
@Loggable(Loggable.DEBUG)
@EqualsAndHashCode(of = { "cmmt" })
final class MkStatuses implements Statuses {
/**
* Commit whose statuses this represents.
*/
private final transient Commit cmmt;

/**
* Ctor.
* @param cmt Commit whose statuses this represents
*/
MkStatuses(
@NotNull(message = "commit can't be NULL")
final Commit cmt
) {
this.cmmt = cmt;
}

@Override
@NotNull(message = "commit is never NULL")
public Commit commit() {
return this.cmmt;
}

@Override
public Status create(
@NotNull(message = "status creation data can't be NULL")
final StatusCreate status
) throws IOException {
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
@NotNull(message = "iterable of statuses is never NULL")
public Iterable<Status> list(
@NotNull(message = "ref can't be NULL") final String ref
) {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
@NotNull(message = "JSON is never NULL")
public JsonObject json() {
throw new UnsupportedOperationException("Yet to be implemented");
}
}
4 changes: 2 additions & 2 deletions src/test/java/com/jcabi/github/RtStatusesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.junit.Test;

/**
* Testcase for RtCommits.
* Testcase for {@link RtStatuses}.
*
* @author Marcin Cylke ([email protected])
* @version $Id$
Expand All @@ -48,7 +48,7 @@
public class RtStatusesTest {

/**
* Tests creating a Commit.
* Tests creating a Status.
*
* @throws Exception when an Error occurs
*/
Expand Down