Skip to content

Commit

Permalink
add test for MkCkeck
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Mar 21, 2023
1 parent 4200429 commit ca9816d
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 186 deletions.
181 changes: 181 additions & 0 deletions src/main/java/com/jcabi/github/Check.java
Expand Up @@ -30,6 +30,8 @@
package com.jcabi.github;

import java.io.IOException;
import java.util.Arrays;
import java.util.Locale;

/**
* Github check.
Expand All @@ -48,4 +50,183 @@ public interface Check {
*/
boolean successful() throws IOException;

/**
* Check status.
* You can read more about it
* @checkstyle LineLengthCheck (1 lines)
* <a href="https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference"> here </a>
*/
enum Status {
/**
* Queued.
*/
QUEUED("queued"),

/**
* In progress.
*/
IN_PROGRESS("in_progress"),

/**
* Completed.
*/
COMPLETED("completed");

/**
* Status.
*/
private final String status;

/**
* Ctor.
* @param stat Status.
*/
Status(final String stat) {
this.status = stat;
}

/**
* Status.
* @return Status.
*/
public String value() {
return this.status;
}

/**
* Get status from string.
* @param value String value.
* @return Status.
*/
public static Status fromString(final String value) {
return Arrays.stream(Status.values())
.filter(stat -> stat.same(value))
.findFirst()
.orElseThrow(
() -> new IllegalArgumentException(
String.format("Invalid value %s for status", value)
)
);
}

/**
* Check if check is finished.
* @return True if check is finished.
*/
boolean finished() {
return this == Status.COMPLETED;
}

/**
* Check if status is the same as value.
* @param value Value.
* @return True if status is the same as value.
*/
boolean same(final String value) {
return this.status.equals(value.toLowerCase(Locale.ROOT));
}
}

/**
* Check conclusion.
* You can read more about it
* @checkstyle LineLengthCheck (1 lines)
* <a href="https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference"> here </a>
*/
enum Conclusion {

/**
* Action required.
*/
ACTION_REQUIRED("action_required"),

/**
* Cancelled.
*/
CANCELLED("cancelled"),

/**
* Failure.
*/
FAILURE("failure"),

/**
* Neutral.
*/
NEUTRAL("neutral"),

/**
* Success.
*/
SUCCESS("success"),

/**
* Skipped.
*/
SKIPPED("skipped"),

/**
* Stale.
*/
STALE("stale"),

/**
* Timed out.
*/
TIMED_OUT("timed_out");

/**
* Conclusion.
*/
private final String conclusion;

/**
* Ctor.
* @param con Conclusion.
*/
Conclusion(final String con) {
this.conclusion = con;
}

/**
* Get conclusion from string.
* @param value String value.
* @return Conclusion.
*/
public static Conclusion fromString(final String value) {
return Arrays.stream(Conclusion.values())
.filter(stat -> stat.same(value))
.findFirst()
.orElseThrow(
() -> new IllegalArgumentException(
String.format("Invalid value %s for conclusion", value)
)
);
}

/**
* Conclusion.
* @return Conclusion.
*/
public String value() {
return this.conclusion;
}

/**
* Check if check is successful.
* @return True if check is successful.
*/
boolean successful() {
return this == Conclusion.SUCCESS;
}

/**
* Check if conclusion is the same as value.
* @param value Value to compare.
* @return True if conclusion is the same as value.
*/
boolean same(final String value) {
return this.conclusion.equals(value.toLowerCase(Locale.ROOT));
}
}
}
172 changes: 1 addition & 171 deletions src/main/java/com/jcabi/github/RtCheck.java
Expand Up @@ -29,9 +29,6 @@
*/
package com.jcabi.github;

import java.util.Arrays;
import java.util.Locale;

/**
* Github check.
*
Expand All @@ -57,10 +54,7 @@ class RtCheck implements Check {
* @param stat Status.
* @param conc Conclusion.
*/
RtCheck(
final String stat,
final String conc
) {
RtCheck(final String stat, final String conc) {
this(Status.fromString(stat), Conclusion.fromString(conc));
}

Expand All @@ -81,168 +75,4 @@ class RtCheck implements Check {
public boolean successful() {
return this.status.finished() && this.conclusion.successful();
}

/**
* Check status.
* You can read more about it
* @checkstyle LineLengthCheck (1 lines)
* <a href="https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference"> here </a>
*/
enum Status {
/**
* Queued.
*/
QUEUED("queued"),

/**
* In progress.
*/
IN_PROGRESS("in_progress"),

/**
* Completed.
*/
COMPLETED("completed");

/**
* Status.
*/
private final String status;

/**
* Ctor.
* @param stat Status.
*/
Status(final String stat) {
this.status = stat;
}

/**
* Check if check is finished.
* @return True if check is finished.
*/
boolean finished() {
return this == Status.COMPLETED;
}

/**
* Get status from string.
* @param value String value.
* @return Status.
*/
static Status fromString(final String value) {
return Arrays.stream(Status.values())
.filter(stat -> stat.same(value))
.findFirst()
.orElseThrow(
() -> new IllegalArgumentException(
String.format("Invalid value %s for status", value)
)
);
}

/**
* Check if status is the same as value.
* @param value Value.
* @return True if status is the same as value.
*/
boolean same(final String value) {
return this.status.equals(value.toLowerCase(Locale.ROOT));
}
}

/**
* Check conclusion.
* You can read more about it
* @checkstyle LineLengthCheck (1 lines)
* <a href="https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference"> here </a>
*/
enum Conclusion {

/**
* Action required.
*/
ACTION_REQUIRED("action_required"),

/**
* Cancelled.
*/
CANCELLED("cancelled"),

/**
* Failure.
*/
FAILURE("failure"),

/**
* Neutral.
*/
NEUTRAL("neutral"),

/**
* Success.
*/
SUCCESS("success"),

/**
* Skipped.
*/
SKIPPED("skipped"),

/**
* Stale.
*/
STALE("stale"),

/**
* Timed out.
*/
TIMED_OUT("timed_out");

/**
* Conclusion.
*/
private final String conclusion;

/**
* Ctor.
* @param con Conclusion.
*/
Conclusion(final String con) {
this.conclusion = con;
}

/**
* Check if check is successful.
* @return True if check is successful.
*/
boolean successful() {
return this == Conclusion.SUCCESS;
}

/**
* Get conclusion from string.
* @param value String value.
* @return Conclusion.
*/
static Conclusion fromString(final String value) {
return Arrays.stream(Conclusion.values())
.filter(stat -> stat.same(value))
.findFirst()
.orElseThrow(
() -> new IllegalArgumentException(
String.format("Invalid value %s for conclusion", value)
)
);
}

/**
* Check if conclusion is the same as value.
* @param value Value to compare.
* @return True if conclusion is the same as value.
*/
boolean same(final String value) {
return this.conclusion.equals(value.toLowerCase(Locale.ROOT));
}
}
}

0 comments on commit ca9816d

Please sign in to comment.