Rename method

This commit is contained in:
Rene Pfeuffer
2019-11-11 16:50:39 +01:00
parent 8e4606cff1
commit f7e42db850
6 changed files with 10 additions and 10 deletions

View File

@@ -69,7 +69,7 @@ public final class BranchCommandBuilder {
} }
public void delete(String branchName) { public void delete(String branchName) {
command.delete(branchName); command.deleteOrClose(branchName);
} }
private BranchCommand command; private BranchCommand command;

View File

@@ -42,5 +42,5 @@ import sonia.scm.repository.api.BranchRequest;
public interface BranchCommand { public interface BranchCommand {
Branch branch(BranchRequest name); Branch branch(BranchRequest name);
void delete(String branchName); void deleteOrClose(String branchName);
} }

View File

@@ -84,7 +84,7 @@ public class GitBranchCommand extends AbstractGitCommand implements BranchComman
} }
@Override @Override
public void delete(String branchName) { public void deleteOrClose(String branchName) {
try (Git gitRepo = new Git(context.open())) { try (Git gitRepo = new Git(context.open())) {
RepositoryHookEvent hookEvent = createBranchHookEvent(BranchHookContextProvider.deleteHookEvent(branchName)); RepositoryHookEvent hookEvent = createBranchHookEvent(BranchHookContextProvider.deleteHookEvent(branchName));
eventBus.post(new PreReceiveRepositoryHookEvent(hookEvent)); eventBus.post(new PreReceiveRepositoryHookEvent(hookEvent));

View File

@@ -73,14 +73,14 @@ public class GitBranchCommandTest extends AbstractGitCommandTestBase {
public void shouldDeleteBranch() throws IOException { public void shouldDeleteBranch() throws IOException {
GitContext context = createContext(); GitContext context = createContext();
String branchToBeDeleted = "squash"; String branchToBeDeleted = "squash";
createCommand().delete(branchToBeDeleted); createCommand().deleteOrClose(branchToBeDeleted);
assertThat(readBranches(context)).filteredOn(b -> b.getName().equals(branchToBeDeleted)).isEmpty(); assertThat(readBranches(context)).filteredOn(b -> b.getName().equals(branchToBeDeleted)).isEmpty();
} }
@Test @Test
public void shouldThrowInternalRepositoryException() { public void shouldThrowInternalRepositoryException() {
String branchToBeDeleted = "master"; String branchToBeDeleted = "master";
assertThrows(InternalRepositoryException.class, () -> createCommand().delete(branchToBeDeleted)); assertThrows(InternalRepositoryException.class, () -> createCommand().deleteOrClose(branchToBeDeleted));
} }
private GitBranchCommand createCommand() { private GitBranchCommand createCommand() {
@@ -118,7 +118,7 @@ public class GitBranchCommandTest extends AbstractGitCommandTestBase {
doNothing().when(eventBus).post(captor.capture()); doNothing().when(eventBus).post(captor.capture());
when(hookContextFactory.createContext(any(), any())).thenAnswer(this::createMockedContext); when(hookContextFactory.createContext(any(), any())).thenAnswer(this::createMockedContext);
createCommand().delete("squash"); createCommand().deleteOrClose("squash");
List<Object> events = captor.getAllValues(); List<Object> events = captor.getAllValues();
assertThat(events.get(0)).isInstanceOf(PreReceiveRepositoryHookEvent.class); assertThat(events.get(0)).isInstanceOf(PreReceiveRepositoryHookEvent.class);

View File

@@ -76,7 +76,7 @@ public class HgBranchCommand extends AbstractCommand implements BranchCommand {
} }
@Override @Override
public void delete(String branchName) { public void deleteOrClose(String branchName) {
try (WorkingCopy<com.aragost.javahg.Repository, com.aragost.javahg.Repository> workingCopy = workdirFactory.createWorkingCopy(getContext(), branchName)) { try (WorkingCopy<com.aragost.javahg.Repository, com.aragost.javahg.Repository> workingCopy = workdirFactory.createWorkingCopy(getContext(), branchName)) {
User currentUser = SecurityUtils.getSubject().getPrincipals().oneByType(User.class); User currentUser = SecurityUtils.getSubject().getPrincipals().oneByType(User.class);

View File

@@ -60,7 +60,7 @@ public class HgBranchCommandTest extends AbstractHgCommandTestBase {
public void shouldCloseBranch() { public void shouldCloseBranch() {
String branchToBeClosed = "test-branch"; String branchToBeClosed = "test-branch";
new HgBranchCommand(cmdContext, repository, workdirFactory).delete(branchToBeClosed); new HgBranchCommand(cmdContext, repository, workdirFactory).deleteOrClose(branchToBeClosed);
assertThat(readBranches()).filteredOn(b -> b.getName().equals(branchToBeClosed)).isEmpty(); assertThat(readBranches()).filteredOn(b -> b.getName().equals(branchToBeClosed)).isEmpty();
} }
@@ -68,8 +68,8 @@ public class HgBranchCommandTest extends AbstractHgCommandTestBase {
public void shouldThrowInternalRepositoryException() { public void shouldThrowInternalRepositoryException() {
String branchToBeClosed = "default"; String branchToBeClosed = "default";
new HgBranchCommand(cmdContext, repository, workdirFactory).delete(branchToBeClosed); new HgBranchCommand(cmdContext, repository, workdirFactory).deleteOrClose(branchToBeClosed);
assertThrows(InternalRepositoryException.class, () -> new HgBranchCommand(cmdContext, repository, workdirFactory).delete(branchToBeClosed)); assertThrows(InternalRepositoryException.class, () -> new HgBranchCommand(cmdContext, repository, workdirFactory).deleteOrClose(branchToBeClosed));
} }
private List<Branch> readBranches() { private List<Branch> readBranches() {