22
33import static org .junit .Assert .assertEquals ;
44import static org .junit .Assert .assertFalse ;
5+ import static org .junit .Assert .assertNotEquals ;
56import static org .junit .Assert .assertNotNull ;
67import static org .junit .Assert .assertTrue ;
78import 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