mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-23 15:00:49 +01:00
implement Modify Command
This commit is contained in:
@@ -7,6 +7,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import sonia.scm.AlreadyExistsException;
|
||||
import sonia.scm.NotFoundException;
|
||||
import sonia.scm.repository.HgHookManager;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.repository.util.WorkdirProvider;
|
||||
@@ -56,8 +57,7 @@ public class HgModifyCommandTest extends AbstractHgCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void shouldCreateFilesWithoutOverwrite() throws IOException {
|
||||
|
||||
File testFile = temporaryFolder.newFile("Answer.txt");
|
||||
File testFile = temporaryFolder.newFile();
|
||||
|
||||
ModifyCommandRequest request = new ModifyCommandRequest();
|
||||
request.addRequest(new ModifyCommandRequest.CreateFileRequest("Answer.txt", testFile, false));
|
||||
@@ -72,20 +72,11 @@ public class HgModifyCommandTest extends AbstractHgCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void shouldOverwriteExistingFiles() throws IOException {
|
||||
|
||||
File testFile = temporaryFolder.newFile("Answer.txt");
|
||||
new FileOutputStream(testFile).write(21);
|
||||
|
||||
ModifyCommandRequest request = new ModifyCommandRequest();
|
||||
request.addRequest(new ModifyCommandRequest.CreateFileRequest("Answer.txt", testFile, false));
|
||||
request.setCommitMessage("I found the answer");
|
||||
request.setAuthor(new Person("Trillian Astra", "trillian@hitchhiker.com"));
|
||||
|
||||
hgModifyCommand.execute(request);
|
||||
File testFile = temporaryFolder.newFile();
|
||||
|
||||
new FileOutputStream(testFile).write(42);
|
||||
ModifyCommandRequest request2 = new ModifyCommandRequest();
|
||||
request2.addRequest(new ModifyCommandRequest.CreateFileRequest("Answer.txt", testFile, true));
|
||||
request2.addRequest(new ModifyCommandRequest.CreateFileRequest("a.txt", testFile, true));
|
||||
request2.setCommitMessage(" Now i really found the answer");
|
||||
request2.setAuthor(new Person("Trillian Astra", "trillian@hitchhiker.com"));
|
||||
|
||||
@@ -93,13 +84,13 @@ public class HgModifyCommandTest extends AbstractHgCommandTestBase {
|
||||
|
||||
assertThat(cmdContext.open().tip().getNode()).isEqualTo(changeSet2);
|
||||
assertThat(cmdContext.open().tip().getModifiedFiles().size()).isEqualTo(1);
|
||||
assertThat(cmdContext.open().tip().getModifiedFiles().get(0)).isEqualTo(testFile.getName());
|
||||
assertThat(cmdContext.open().tip().getModifiedFiles().get(0)).isEqualTo("a.txt");
|
||||
}
|
||||
|
||||
@Test(expected = AlreadyExistsException.class)
|
||||
public void shouldThrowFileAlreadyExistsException() throws IOException {
|
||||
|
||||
File testFile = temporaryFolder.newFile("Answer.txt");
|
||||
File testFile = temporaryFolder.newFile();
|
||||
new FileOutputStream(testFile).write(21);
|
||||
|
||||
ModifyCommandRequest request = new ModifyCommandRequest();
|
||||
@@ -117,4 +108,62 @@ public class HgModifyCommandTest extends AbstractHgCommandTestBase {
|
||||
|
||||
hgModifyCommand.execute(request2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldModifyExistingFile() throws IOException {
|
||||
File testFile = temporaryFolder.newFile("a.txt");
|
||||
|
||||
new FileOutputStream(testFile).write(42);
|
||||
ModifyCommandRequest request2 = new ModifyCommandRequest();
|
||||
request2.addRequest(new ModifyCommandRequest.ModifyFileRequest("a.txt", testFile));
|
||||
request2.setCommitMessage(" Now i really found the answer");
|
||||
request2.setAuthor(new Person("Trillian Astra", "trillian@hitchhiker.com"));
|
||||
|
||||
String changeSet2 = hgModifyCommand.execute(request2);
|
||||
|
||||
assertThat(cmdContext.open().tip().getNode()).isEqualTo(changeSet2);
|
||||
assertThat(cmdContext.open().tip().getModifiedFiles().size()).isEqualTo(1);
|
||||
assertThat(cmdContext.open().tip().getModifiedFiles().get(0)).isEqualTo(testFile.getName());
|
||||
}
|
||||
|
||||
@Test(expected = NotFoundException.class)
|
||||
public void shouldThrowNotFoundExceptionIfFileDoesNotExist() throws IOException {
|
||||
File testFile = temporaryFolder.newFile("Answer.txt");
|
||||
|
||||
new FileOutputStream(testFile).write(42);
|
||||
ModifyCommandRequest request2 = new ModifyCommandRequest();
|
||||
request2.addRequest(new ModifyCommandRequest.ModifyFileRequest("Answer.txt", testFile));
|
||||
request2.setCommitMessage(" Now i really found the answer");
|
||||
request2.setAuthor(new Person("Trillian Astra", "trillian@hitchhiker.com"));
|
||||
|
||||
hgModifyCommand.execute(request2);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void shouldThrowNPEIfAuthorIsMissing() throws IOException {
|
||||
File testFile = temporaryFolder.newFile();
|
||||
|
||||
ModifyCommandRequest request = new ModifyCommandRequest();
|
||||
request.addRequest(new ModifyCommandRequest.CreateFileRequest("Answer.txt", testFile, false));
|
||||
request.setCommitMessage("I found the answer");
|
||||
hgModifyCommand.execute(request);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void shouldThrowNPEIfCommitMessageIsMissing() throws IOException {
|
||||
File testFile = temporaryFolder.newFile();
|
||||
|
||||
ModifyCommandRequest request = new ModifyCommandRequest();
|
||||
request.addRequest(new ModifyCommandRequest.CreateFileRequest("Answer.txt", testFile, false));
|
||||
request.setAuthor(new Person("Trillian Astra", "trillian@hitchhiker.com"));
|
||||
hgModifyCommand.execute(request);
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void shouldThrowIndexOutOfBoundExceptionIfRequestIsMissing() throws IOException {
|
||||
ModifyCommandRequest request = new ModifyCommandRequest();
|
||||
request.setCommitMessage("I found the answer");
|
||||
request.setAuthor(new Person("Trillian Astra", "trillian@hitchhiker.com"));
|
||||
hgModifyCommand.execute(request);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user