Skip to content

Commit

Permalink
Merge 0333051 into fb6f37a
Browse files Browse the repository at this point in the history
  • Loading branch information
patbos committed Oct 22, 2014
2 parents fb6f37a + 0333051 commit 526106a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static List<Change> getChanges(AbstractBuild<?, ?> build) {
changeLink = link.toExternalForm();
}
} catch (IOException e) {
LOG.log(Level.WARNING, "Could not get changeset link", e);
LOG.log(Level.WARNING, "Could not get changeset link for: " + build.getProject().getFullDisplayName() + " " + build.getDisplayName(), e);
}
}
result.add(new Change(user, entry.getMsg(), entry.getCommitId(), changeLink));
Expand Down
33 changes: 32 additions & 1 deletion src/test/java/se/diabol/jenkins/pipeline/domain/ChangeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@

import hudson.model.AbstractBuild;
import hudson.model.FreeStyleProject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.FakeChangeLogSCM;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockFolder;
import se.diabol.jenkins.pipeline.test.FakeRepositoryBrowserSCM;
import se.diabol.jenkins.pipeline.test.MeanFakeRepositoryBrowserSCM;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.Logger;
import java.util.logging.StreamHandler;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand All @@ -37,6 +46,24 @@ public class ChangeTest {
@Rule
public JenkinsRule jenkins = new JenkinsRule();


private static Logger log = Logger.getLogger(Change.class.getName()); // matches the logger in the affected class
private static OutputStream logCapturingStream;
private static StreamHandler customLogHandler;

@Before
public void attachLogCapturer() {
logCapturingStream = new ByteArrayOutputStream();
Handler[] handlers = log.getParent().getHandlers();
customLogHandler = new StreamHandler(logCapturingStream, handlers[0].getFormatter());
log.addHandler(customLogHandler);
}

public String getTestCapturedLog() throws IOException {
customLogHandler.flush();
return logCapturingStream.toString();
}

@Test
public void testGetChangesNoBrowser() throws Exception {
FreeStyleProject project = jenkins.createFreeStyleProject("build");
Expand Down Expand Up @@ -77,7 +104,8 @@ public void testGetChangesWithBrowser() throws Exception {

@Test
public void testGetChangesWithBrowserThrowIOException() throws Exception {
FreeStyleProject project = jenkins.createFreeStyleProject("build");
MockFolder folder = jenkins.createFolder("Folder");
FreeStyleProject project = folder.createProject(FreeStyleProject.class, "build");
MeanFakeRepositoryBrowserSCM scm = new MeanFakeRepositoryBrowserSCM();
scm.addChange().withAuthor("test-user").withMsg("Fixed bug");
project.setScm(scm);
Expand All @@ -92,6 +120,9 @@ public void testGetChangesWithBrowserThrowIOException() throws Exception {
assertEquals("test-user", change.getAuthor().getName());
assertNull(change.getCommitId());
assertNull(change.getChangeLink());

String capturedLog = getTestCapturedLog();
Assert.assertTrue(capturedLog.contains("Could not get changeset link for: Folder » build #1"));
}


Expand Down

0 comments on commit 526106a

Please sign in to comment.