Skip to content

Commit

Permalink
SONAR-6364 Line number should be unset on closed issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Brandhof committed Apr 16, 2015
1 parent c0a1887 commit 8ad882a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
Expand Up @@ -30,6 +30,7 @@ interface Context {
Context setAssignee(@Nullable User user);
Context setResolution(@Nullable String s);
Context setCloseDate(boolean b);
Context setLine(@Nullable Integer line);
}

void execute(Context context);
Expand Down
Expand Up @@ -77,7 +77,13 @@ public Function.Context setResolution(@Nullable String s) {
@Override
public Function.Context setCloseDate(boolean b) {
updater.setCloseDate(issue, b ? changeContext.date() : null, changeContext);
return null;
return this;
}

@Override
public Function.Context setLine(@Nullable Integer line) {
updater.setLine(issue, line);
return this;
}
}
}
Expand Up @@ -131,25 +131,25 @@ private void buildAutomaticTransitions(StateMachine.Builder builder) {
builder.transition(Transition.builder("automaticclose")
.from(Issue.STATUS_OPEN).to(Issue.STATUS_CLOSED)
.conditions(new IsEndOfLife(true))
.functions(new SetEndOfLifeResolution(), new SetCloseDate(true))
.functions(new SetEndOfLife(), new SetCloseDate(true))
.automatic()
.build())
.transition(Transition.builder("automaticclose")
.from(Issue.STATUS_REOPENED).to(Issue.STATUS_CLOSED)
.conditions(new IsEndOfLife(true))
.functions(new SetEndOfLifeResolution(), new SetCloseDate(true))
.functions(new SetEndOfLife(), new SetCloseDate(true))
.automatic()
.build())
.transition(Transition.builder("automaticclose")
.from(Issue.STATUS_CONFIRMED).to(Issue.STATUS_CLOSED)
.conditions(new IsEndOfLife(true))
.functions(new SetEndOfLifeResolution(), new SetCloseDate(true))
.functions(new SetEndOfLife(), new SetCloseDate(true))
.automatic()
.build())
.transition(Transition.builder("automaticclose")
.from(Issue.STATUS_RESOLVED).to(Issue.STATUS_CLOSED)
.conditions(new IsEndOfLife(true))
.functions(new SetEndOfLifeResolution(), new SetCloseDate(true))
.functions(new SetEndOfLife(), new SetCloseDate(true))
.automatic()
.build())
.transition(Transition.builder("automaticclosemanual")
Expand Down
Expand Up @@ -22,7 +22,7 @@
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;

public class SetEndOfLifeResolution implements Function {
public class SetEndOfLife implements Function {
@Override
public void execute(Context context) {
DefaultIssue issue = (DefaultIssue) context.issue();
Expand All @@ -34,5 +34,10 @@ public void execute(Context context) {
} else {
context.setResolution(Issue.RESOLUTION_FIXED);
}

// closed issues are not "tracked" -> the line number does not evolve anymore
// when code changes. That's misleading for end-users, so line number
// is unset.
context.setLine(null);
}
}
Expand Up @@ -27,10 +27,10 @@
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;

public class SetEndOfLifeResolutionTest {
public class SetEndOfLifeTest {

Function.Context context = mock(Function.Context.class);
SetEndOfLifeResolution function = new SetEndOfLifeResolution();
SetEndOfLife function = new SetEndOfLife();

@Test
public void should_resolve_as_fixed() throws Exception {
Expand Down Expand Up @@ -60,4 +60,12 @@ public void should_fail_if_issue_is_not_resolved() throws Exception {
verify(context, never()).setResolution(anyString());
}
}

@Test
public void line_number_must_be_unset() throws Exception {
Issue issue = new DefaultIssue().setEndOfLife(true).setLine(10);
when(context.issue()).thenReturn(issue);
function.execute(context);
verify(context).setLine(null);
}
}

0 comments on commit 8ad882a

Please sign in to comment.