|
5 | 5 | package com.jcabi.github.mock; |
6 | 6 |
|
7 | 7 | import com.jcabi.github.Commit; |
| 8 | +import com.jcabi.github.Commits; |
8 | 9 | import jakarta.json.Json; |
9 | 10 | import jakarta.json.JsonArray; |
10 | 11 | import jakarta.json.JsonObject; |
@@ -46,4 +47,62 @@ void createsMkCommit() throws IOException { |
46 | 47 | Matchers.equalTo("12ahscba") |
47 | 48 | ); |
48 | 49 | } |
| 50 | + |
| 51 | + /** |
| 52 | + * MkCommits.create() must persist the new commit's sha in storage so |
| 53 | + * that subsequent calls (e.g. json(), get()) can find the commit. |
| 54 | + * @throws IOException if there is any I/O problem |
| 55 | + */ |
| 56 | + @Test |
| 57 | + void persistsCreatedCommitSha() throws IOException { |
| 58 | + final String sha = "9e1f3c7b8d4a5e6f7c2d1b0a9e8f7d6c5b4a3210"; |
| 59 | + final Commits commits = new MkGitHub().randomRepo().git().commits(); |
| 60 | + commits.create( |
| 61 | + Json.createObjectBuilder() |
| 62 | + .add("message", "persisted commit message") |
| 63 | + .add("sha", sha) |
| 64 | + .add("tree", "treesha9e1f3c7b8d4a") |
| 65 | + .add( |
| 66 | + "parents", |
| 67 | + Json.createArrayBuilder().add("parentsha0123456789").build() |
| 68 | + ) |
| 69 | + .add( |
| 70 | + "author", |
| 71 | + Json.createObjectBuilder() |
| 72 | + .add("name", "Alice") |
| 73 | + .add("email", "alice@example.com") |
| 74 | + .add("date", "2024-01-15T12:30:00+00:00") |
| 75 | + .build() |
| 76 | + ) |
| 77 | + .build() |
| 78 | + ); |
| 79 | + MatcherAssert.assertThat( |
| 80 | + "sha must be persisted in storage", |
| 81 | + commits.get(sha).json().getString("sha"), |
| 82 | + Matchers.equalTo(sha) |
| 83 | + ); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * MkCommits.create() must persist the commit message in storage. |
| 88 | + * @throws IOException if there is any I/O problem |
| 89 | + */ |
| 90 | + @Test |
| 91 | + void persistsCreatedCommitMessage() throws IOException { |
| 92 | + final String sha = "abcdef0123456789abcdef0123456789abcdef01"; |
| 93 | + final String message = "another persisted message"; |
| 94 | + final Commits commits = new MkGitHub().randomRepo().git().commits(); |
| 95 | + commits.create( |
| 96 | + Json.createObjectBuilder() |
| 97 | + .add("message", message) |
| 98 | + .add("sha", sha) |
| 99 | + .add("tree", "treesha-abcdef-0123") |
| 100 | + .build() |
| 101 | + ); |
| 102 | + MatcherAssert.assertThat( |
| 103 | + "message must be persisted in storage", |
| 104 | + commits.get(sha).json().getString("message"), |
| 105 | + Matchers.equalTo(message) |
| 106 | + ); |
| 107 | + } |
49 | 108 | } |
0 commit comments