Skip to content

Commit

Permalink
#1203 REPO_RENAMED handled and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Aug 10, 2021
1 parent ba9e091 commit ad07e3e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
6 changes: 6 additions & 0 deletions self-api/src/main/java/com/selfxdsd/api/ProjectManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,10 @@ public interface ProjectManager {
* @param event Event.
*/
void comment(final Event event);

/**
* Handle renaming of a Project.
* @param event Event.
*/
void renamedProject(final Event event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,11 @@ public void comment(final Event event) {
}
}

@Override
public void renamedProject(final Event event) {
event.project().rename(event.repoNewName());
}

@Override
public int hashCode() {
return this.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
* It should decide what kind of event has occurred and delegate it
* further to the ProjectManager who will deal with it. We still need
* the Issue Assigned case and Comment Created case.
* @todo #1199:60min Add the REPO_RENAMED case to the resolve(...) method
* and forward the call to the ProjectManager to take care of it.
*/
public final class StoredProject implements Project {

Expand Down Expand Up @@ -195,6 +193,9 @@ public void resolve(final Event event) {
case Event.Type.ISSUE_COMMENT:
this.projectManager.comment(event);
break;
case Event.Type.REPO_RENAMED:
this.projectManager.renamedProject(event);
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,35 @@ public void handlesAssignedTasksEventMissedDeadline() {
+ "I will assign it to someone else soon.");
}

/**
* StoredProjectManager can rename a Project.
*/
@Test
public void handlesRepoRenamed() {
final Project project = Mockito.mock(Project.class);

final Event event = Mockito.mock(Event.class);
Mockito.when(event.project()).thenReturn(project);
Mockito.when(event.repoNewName()).thenReturn("newName");

final ProjectManager manager = new StoredProjectManager(
1,
"123",
"zoeself",
Provider.Names.GITHUB,
"123token",
8,
5,
Mockito.mock(Storage.class)
);

manager.renamedProject(event);

Mockito.verify(event, Mockito.times(1)).project();
Mockito.verify(event, Mockito.times(1)).repoNewName();
Mockito.verify(project, Mockito.times(1)).rename("newName");
}

/**
* Mock a Repo for test.
*
Expand Down

1 comment on commit ad07e3e

@zoeself
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amihaiemil I've closed the Issues [#1204] since their to-dos disappeared from the code.

The to-dos may have been removed in an earlier commit, but I've found it just now.

Please sign in to comment.