Skip to content

Commit b5db32f

Browse files
Add test for nullable conclusion
1 parent 19334d4 commit b5db32f

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/main/java/com/jcabi/github/RtChecks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private static String getOrUndefined(
139139
final JsonObject check
140140
) {
141141
final String res;
142-
if (check.containsKey(key)) {
142+
if (check.containsKey(key) && !check.isNull(key)) {
143143
res = check.getString(key);
144144
} else {
145145
res = Check.UNDEFINED_VALUE;

src/test/java/com/jcabi/github/RtChecksTest.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import javax.json.Json;
4242
import javax.json.JsonArrayBuilder;
4343
import javax.json.JsonObjectBuilder;
44+
import javax.json.JsonValue;
4445
import org.hamcrest.MatcherAssert;
4546
import org.hamcrest.Matchers;
4647
import org.junit.Assert;
@@ -62,6 +63,11 @@ public final class RtChecksTest {
6263
*/
6364
private static final String CONCLUSION_KEY = "conclusion";
6465

66+
/**
67+
* Status key in json check.
68+
*/
69+
private static final String STATUS_KEY = "status";
70+
6571
/**
6672
* The rule for skipping test if there's BindException.
6773
* @checkstyle VisibilityModifierCheck (3 lines)
@@ -183,6 +189,45 @@ public void retrievesUnfinishedChecksWithoutConclusion()
183189
}
184190
}
185191

192+
/**
193+
* Checks that library can handle unfinished checks.
194+
* @throws IOException If some I/O problem happens.
195+
*/
196+
@Test
197+
public void retrievesUnfinishedChecksWithNullableConclusion()
198+
throws IOException {
199+
try (final MkContainer container = new MkGrizzlyContainer()
200+
.next(
201+
new MkAnswer.Simple(
202+
HttpURLConnection.HTTP_OK,
203+
RtChecksTest.jsonChecks(
204+
RtChecksTest.jsonCheck()
205+
.add(
206+
RtChecksTest.CONCLUSION_KEY,
207+
JsonValue.NULL
208+
).add(
209+
RtChecksTest.STATUS_KEY,
210+
Check.Status.QUEUED.value()
211+
)
212+
)
213+
)
214+
).start(this.resource.port())
215+
) {
216+
final Checks checks = new RtChecks(
217+
new JdkRequest(container.home()),
218+
this.repo().pulls().get(0)
219+
);
220+
final Collection<? extends Check> all = checks.all();
221+
MatcherAssert.assertThat(all, Matchers.hasSize(1));
222+
for (final Check check : all) {
223+
MatcherAssert.assertThat(
224+
check.successful(),
225+
Matchers.is(false)
226+
);
227+
}
228+
}
229+
}
230+
186231
/**
187232
* Checks that library can handle unfinished checks.
188233
* @throws IOException If some I/O problem happens.
@@ -223,7 +268,10 @@ public void retrievesUnfinishedChecksWithoutStatusAndConclusion()
223268
private static String jsonWithCheckRuns() {
224269
return RtChecksTest.jsonChecks(
225270
RtChecksTest.jsonCheck()
226-
.add("status", Check.Status.COMPLETED.value())
271+
.add(
272+
RtChecksTest.STATUS_KEY,
273+
Check.Status.COMPLETED.value()
274+
)
227275
.add(
228276
RtChecksTest.CONCLUSION_KEY,
229277
Check.Conclusion.SUCCESS.value()

0 commit comments

Comments
 (0)