Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-23939] Updated FindBugs and unit tests to verify changes to …
…support maven builds.
  • Loading branch information
lewisvail3 committed Mar 2, 2016
1 parent a4b0497 commit acfc289
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 2 deletions.
Expand Up @@ -10,6 +10,7 @@
import hudson.plugins.analysis.core.HealthDescriptor;
import hudson.plugins.analysis.util.model.Priority;
import hudson.plugins.cigame.model.RuleResult;
import hudson.plugins.findbugs.FindBugsMavenResultAction;
import hudson.plugins.findbugs.FindBugsResult;
import hudson.plugins.findbugs.FindBugsResultAction;

Expand Down Expand Up @@ -38,6 +39,22 @@ public void assertFailedBuildsIsWorthZeroPoints() {
assertThat("Points should be zero", ruleResult.getPoints(), is((double) 0));
}

@Test
public void assertFailedMavenBuildsIsWorthZeroPoints() {
AbstractBuild build = mock(AbstractBuild.class);
when(build.getResult()).thenReturn(Result.FAILURE);
addMavenFindBugsWarnings(build, 0);

AbstractBuild prevBuild = mock(AbstractBuild.class);
when(prevBuild.getResult()).thenReturn(Result.SUCCESS);
addMavenFindBugsWarnings(prevBuild, 7);

FixedFindBugsWarningsRule rule = new FixedFindBugsWarningsRule(Priority.LOW, 100);
RuleResult ruleResult = rule.evaluate(prevBuild, build);
assertNotNull("Rule result must not be null", ruleResult);
assertThat("Points should be zero", ruleResult.getPoints(), is((double) 0));
}

@Test
public void assertNoPreviousBuildIsWorthZeroPoints() {
AbstractBuild build = mock(AbstractBuild.class);
Expand All @@ -51,6 +68,19 @@ public void assertNoPreviousBuildIsWorthZeroPoints() {
assertThat("Points should be zero", ruleResult.getPoints(), is((double) 0));
}

@Test
public void assertNoPreviousMavenBuildIsWorthZeroPoints() {
AbstractBuild build = mock(AbstractBuild.class);
when(build.getResult()).thenReturn(Result.FAILURE);
when(build.getPreviousBuild()).thenReturn(null);
addMavenFindBugsWarnings(build, 0);

FixedFindBugsWarningsRule rule = new FixedFindBugsWarningsRule(Priority.LOW, 100);
RuleResult ruleResult = rule.evaluate(null, build);
assertNotNull("Rule result must not be null", ruleResult);
assertThat("Points should be zero", ruleResult.getPoints(), is((double) 0));
}

@Test
public void assertIfPreviousBuildFailedResultIsWorthZeroPoints() {
AbstractBuild build = mock(AbstractBuild.class);
Expand All @@ -75,6 +105,30 @@ public void assertIfPreviousBuildFailedResultIsWorthZeroPoints() {
assertThat("Points should be 0", ruleResult.getPoints(), is(0d));
}

@Test
public void assertIfPreviousMavenBuildFailedResultIsWorthZeroPoints() {
AbstractBuild build = mock(AbstractBuild.class);
AbstractBuild previousBuild = mock(AbstractBuild.class);
when(build.getPreviousBuild()).thenReturn(previousBuild);
when(build.getResult()).thenReturn(Result.SUCCESS);
when(previousBuild.getResult()).thenReturn(Result.FAILURE);
FindBugsResult result = mock(FindBugsResult.class);
FindBugsResult previosResult = mock(FindBugsResult.class);
FindBugsMavenResultAction action = new FindBugsMavenResultAction(build, mock(HealthDescriptor.class), "UTF-8", result);
FindBugsMavenResultAction previousAction = new FindBugsMavenResultAction(previousBuild, mock(HealthDescriptor.class), "UTF-8", previosResult);
when(build.getActions(FindBugsMavenResultAction.class)).thenReturn(Arrays.asList(action));
when(build.getAction(FindBugsMavenResultAction.class)).thenReturn(action);
when(previousBuild.getAction(FindBugsMavenResultAction.class)).thenReturn(previousAction);
when(previousBuild.getActions(FindBugsMavenResultAction.class)).thenReturn(Arrays.asList(previousAction));

when(result.getNumberOfAnnotations(Priority.LOW)).thenReturn(5);
when(previosResult.getNumberOfAnnotations(Priority.LOW)).thenReturn(10);

RuleResult ruleResult = new FixedFindBugsWarningsRule(Priority.LOW, -4).evaluate(previousBuild, build);
assertNotNull("Rule result must not be null", ruleResult);
assertThat("Points should be 0", ruleResult.getPoints(), is(0d));
}

@Test
public void assertIfPreviousHasErrorsFailedResultIsWorthZeroPoints() {
AbstractBuild build = mock(AbstractBuild.class);
Expand Down Expand Up @@ -104,7 +158,7 @@ public void assertIfPreviousHasErrorsFailedResultIsWorthZeroPoints() {
public void assertRemovedMavenModuleCountsAsFixed() {
AbstractBuild previousBuild = mock(MavenBuild.class);
when(previousBuild.getResult()).thenReturn(Result.SUCCESS);
addFindBugsWarnings(previousBuild, 6);
addMavenFindBugsWarnings(previousBuild, 6);

RuleResult ruleResult= new FixedFindBugsWarningsRule(Priority.LOW, 1).evaluate(previousBuild, null);
assertNotNull(ruleResult);
Expand All @@ -118,4 +172,12 @@ private static void addFindBugsWarnings(AbstractBuild<?, ?> build, int numberOfW

when(result.getNumberOfAnnotations(Priority.LOW)).thenReturn(numberOfWarnings);
}

private static void addMavenFindBugsWarnings(AbstractBuild<?, ?> build, int numberOfWarnings) {
FindBugsResult result = mock(FindBugsResult.class);
FindBugsMavenResultAction action = new FindBugsMavenResultAction(build, mock(HealthDescriptor.class), "UTF-8", result);
when(build.getActions(FindBugsMavenResultAction.class)).thenReturn(Arrays.asList(action));

when(result.getNumberOfAnnotations(Priority.LOW)).thenReturn(numberOfWarnings);
}
}
Expand Up @@ -12,6 +12,7 @@
import hudson.plugins.analysis.core.HealthDescriptor;
import hudson.plugins.analysis.util.model.Priority;
import hudson.plugins.cigame.model.RuleResult;
import hudson.plugins.findbugs.FindBugsMavenResultAction;
import hudson.plugins.findbugs.FindBugsResult;
import hudson.plugins.findbugs.FindBugsResultAction;

Expand All @@ -38,6 +39,22 @@ public void assertFailedBuildsIsWorthZeroPoints() {
assertThat("Points should be zero", ruleResult.getPoints(), is((double) 0));
}

@Test
public void assertFailedMavenBuildsIsWorthZeroPoints() {
AbstractBuild build = mock(AbstractBuild.class);
when(build.getResult()).thenReturn(Result.FAILURE);
addMavenFindBugsWarnings(build, 10);

AbstractBuild prevBuild = mock(AbstractBuild.class);
when(prevBuild.getResult()).thenReturn(Result.SUCCESS);
addMavenFindBugsWarnings(prevBuild, 5);

NewFindBugsWarningsRule rule = new NewFindBugsWarningsRule(Priority.LOW, 100);
RuleResult ruleResult = rule.evaluate(prevBuild, build);
assertNotNull("Rule result must not be null", ruleResult);
assertThat("Points should be zero", ruleResult.getPoints(), is((double) 0));
}

@Test
public void assertNoPreviousBuildIsWorthZeroPoints() {
AbstractBuild build = mock(AbstractBuild.class);
Expand All @@ -51,6 +68,19 @@ public void assertNoPreviousBuildIsWorthZeroPoints() {
assertThat("Points should be zero", ruleResult.getPoints(), is((double) 0));
}

@Test
public void assertNoPreviousMavenBuildIsWorthZeroPoints() {
AbstractBuild build = mock(AbstractBuild.class);
when(build.getResult()).thenReturn(Result.FAILURE);
when(build.getPreviousBuild()).thenReturn(null);
addMavenFindBugsWarnings(build, 42);

NewFindBugsWarningsRule rule = new NewFindBugsWarningsRule(Priority.LOW, 100);
RuleResult ruleResult = rule.evaluate(null, build);
assertNotNull("Rule result must not be null", ruleResult);
assertThat("Points should be zero", ruleResult.getPoints(), is((double) 0));
}

@Test
public void assertIfPreviousBuildFailedResultIsWorthZeroPoints() {
AbstractBuild build = mock(AbstractBuild.class);
Expand All @@ -73,6 +103,28 @@ public void assertIfPreviousBuildFailedResultIsWorthZeroPoints() {
assertThat("Points should be 0", ruleResult.getPoints(), is(0d));
}

@Test
public void assertIfPreviousMavenBuildFailedResultIsWorthZeroPoints() {
AbstractBuild build = mock(AbstractBuild.class);
AbstractBuild previousBuild = mock(AbstractBuild.class);
when(build.getPreviousBuild()).thenReturn(previousBuild);
when(build.getResult()).thenReturn(Result.SUCCESS);
when(previousBuild.getResult()).thenReturn(Result.FAILURE);
FindBugsResult result = mock(FindBugsResult.class);
FindBugsResult previosResult = mock(FindBugsResult.class);
FindBugsMavenResultAction action = new FindBugsMavenResultAction(build, mock(HealthDescriptor.class), "UTF-8", result);
FindBugsMavenResultAction previousAction = new FindBugsMavenResultAction(previousBuild,mock(HealthDescriptor.class), "UTF-8", previosResult);
when(build.getActions(FindBugsMavenResultAction.class)).thenReturn(Arrays.asList(action));
when(previousBuild.getActions(FindBugsMavenResultAction.class)).thenReturn(Arrays.asList(previousAction));

when(result.getNumberOfAnnotations(Priority.LOW)).thenReturn(10);
when(previosResult.getNumberOfAnnotations(Priority.LOW)).thenReturn(5);

RuleResult ruleResult = new NewFindBugsWarningsRule(Priority.LOW, -4).evaluate(previousBuild, build);
assertNotNull("Rule result must not be null", ruleResult);
assertThat("Points should be 0", ruleResult.getPoints(), is(0d));
}

@Test
public void assertIfPreviousHasErrorsResultIsWorthZeroPoints() {
AbstractBuild build = mock(AbstractBuild.class);
Expand Down Expand Up @@ -100,7 +152,7 @@ public void assertIfPreviousHasErrorsResultIsWorthZeroPoints() {
public void assertNewMavenModuleCountsAsNewWarnings() {
AbstractBuild build = mock(MavenBuild.class);
when(build.getResult()).thenReturn(Result.SUCCESS);
addFindBugsWarnings(build, 7);
addMavenFindBugsWarnings(build, 7);

RuleResult ruleResult = new NewFindBugsWarningsRule(Priority.LOW, -1).evaluate(null, build);
assertNotNull(ruleResult);
Expand All @@ -114,4 +166,12 @@ private static void addFindBugsWarnings(AbstractBuild<?, ?> build, int numberOfW

when(result.getNumberOfAnnotations(Priority.LOW)).thenReturn(numberOfWarnings);
}

private static void addMavenFindBugsWarnings(AbstractBuild<?, ?> build, int numberOfWarnings) {
FindBugsResult result = mock(FindBugsResult.class);
FindBugsMavenResultAction action = new FindBugsMavenResultAction(build, mock(HealthDescriptor.class), "UTF-8", result);
when(build.getActions(FindBugsMavenResultAction.class)).thenReturn(Arrays.asList(action));

when(result.getNumberOfAnnotations(Priority.LOW)).thenReturn(numberOfWarnings);
}
}

0 comments on commit acfc289

Please sign in to comment.