Skip to content

Commit f3881bd

Browse files
committed
Added test for revertCommit() (#355).
1 parent 13a63bb commit f3881bd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/test/java/org/gitlab4j/api/TestCommitsApi.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertNotEquals;
56
import static org.junit.Assert.assertNotNull;
67
import static org.junit.Assert.assertTrue;
78
import static org.junit.Assert.fail;
@@ -287,4 +288,37 @@ public void testCreateCommitCreateWithNoContent() throws GitLabApiException {
287288
} catch (GitLabApiException ignore) {
288289
}
289290
}
291+
292+
@Test
293+
public void testRevertCommit() throws GitLabApiException {
294+
295+
// Make sure the file to create does not exist.
296+
String filePath = TEST_CREATE_COMMIT_FILEPATH + ".test";
297+
if (gitLabApi.getRepositoryFileApi().getOptionalFile(testProject, filePath, "master").isPresent()) {
298+
gitLabApi.getRepositoryFileApi().deleteFile(testProject, filePath, "master", "Deleted test file");
299+
}
300+
301+
// Arrange
302+
CommitAction commitAction = new CommitAction()
303+
.withAction(Action.CREATE)
304+
.withContent("This is the original data in the file")
305+
.withFilePath(filePath);
306+
307+
// Act
308+
Commit commit = gitLabApi.getCommitsApi().createCommit(
309+
testProject, "master", "Testing createCommit() create action", null, null, null, commitAction);
310+
311+
// Assert
312+
assertNotNull(commit);
313+
Optional<RepositoryFile> repoFile = gitLabApi.getRepositoryFileApi().getOptionalFile(testProject, filePath, "master");
314+
assertTrue(repoFile.isPresent());
315+
316+
// Act
317+
Commit revertedCommit = gitLabApi.getCommitsApi().revertCommit(testProject, commit.getId(), "master");
318+
319+
// Assert
320+
assertNotEquals(commit.getId(), revertedCommit.getId());
321+
repoFile = gitLabApi.getRepositoryFileApi().getOptionalFile(testProject, filePath, "master");
322+
assertFalse(repoFile.isPresent());
323+
}
290324
}

0 commit comments

Comments
 (0)