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-11041
  • Loading branch information
finalspy committed Apr 18, 2012
1 parent fb30db1 commit 8d7af4a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
31 changes: 18 additions & 13 deletions src/main/java/hudson/plugins/cigame/model/ScoreCard.java
Expand Up @@ -3,8 +3,8 @@
import hudson.maven.MavenBuild;
import hudson.maven.MavenModule;
import hudson.maven.MavenModuleSetBuild;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.plugins.cigame.util.BuildUtil;

import java.util.ArrayList;
Expand Down Expand Up @@ -38,18 +38,23 @@ public void record(AbstractBuild<?, ?> build, RuleSet ruleset, BuildListener lis

List<Score> scoresForBuild = new LinkedList<Score>();
for (Rule rule : ruleset.getRules()) {
if (listener != null) {
listener.getLogger().append("[ci-game] evaluating rule: " + rule.getName() + "\n");
}
RuleResult<?> result = evaluate(build, rule);
if ((result != null) && (result.getPoints() != 0)) {
Score score = new Score(ruleset.getName(), rule.getName(), result.getPoints(), result.getDescription());
scoresForBuild.add(score);

if (listener != null) {
listener.getLogger().append("[ci-game] scored: " + score.getValue() + "\n");
}
}
if (null != rule){
if (listener != null) {
listener.getLogger().append("[ci-game] evaluating rule: " + rule.getName() + "\n");
}
RuleResult<?> result = evaluate(build, rule);
if ((result != null) && (result.getPoints() != 0)) {
Score score = new Score(ruleset.getName(), rule.getName(), result.getPoints(), result.getDescription());
scoresForBuild.add(score);
if (listener != null) {
listener.getLogger().append("[ci-game] scored: " + score.getValue() + "\n");
}
}
} else {
if (listener != null) {
listener.getLogger().append("[ci-game] null rule encountered\n");
}
}
}

// prevent ConcurrentModificationExceptions for e.g. matrix builds (see JENKINS-11498):
Expand Down
21 changes: 16 additions & 5 deletions src/test/java/hudson/plugins/cigame/model/ScoreCardTest.java
@@ -1,12 +1,15 @@
package hudson.plugins.cigame.model;

import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import hudson.model.AbstractBuild;

import java.util.ArrayList;
import java.util.Arrays;

import hudson.model.AbstractBuild;
import java.util.List;

import org.junit.Test;

Expand All @@ -27,6 +30,14 @@ public void assertThatEmptyRuleResultIsNotUsed() {
assertThat(card.getScores().size(), is(0));
}

@Test
public void assertRuleNull(){
List<Rule> liste = new ArrayList<Rule>();
liste.add(null);
ScoreCard card = new ScoreCard();
card.record(mock(AbstractBuild.class), new RuleSet("test", liste), null);
}

@Test
public void assertEmptyRuleBookDoesNotThrowIllegalException() {
ScoreCard scoreCard = new ScoreCard();
Expand Down

0 comments on commit 8d7af4a

Please sign in to comment.