diff --git a/src/com/googlecode/yatspec/rendering/LinkingNoteRenderer.java b/src/com/googlecode/yatspec/rendering/LinkingNoteRenderer.java index 12b1a169..28c4c141 100644 --- a/src/com/googlecode/yatspec/rendering/LinkingNoteRenderer.java +++ b/src/com/googlecode/yatspec/rendering/LinkingNoteRenderer.java @@ -1,16 +1,23 @@ package com.googlecode.yatspec.rendering; import com.googlecode.totallylazy.Callable1; -import com.googlecode.totallylazy.Sequence; import com.googlecode.yatspec.junit.LinkingNote; +import com.googlecode.yatspec.rendering.Renderer; + +import java.io.File; import static com.googlecode.totallylazy.Sequences.sequence; -import static com.googlecode.yatspec.junit.SpecRunner.outputDirectory; import static com.googlecode.yatspec.parsing.Text.wordify; -import static com.googlecode.yatspec.rendering.html.HtmlResultRenderer.htmlResultFile; +import static com.googlecode.yatspec.rendering.html.HtmlResultRenderer.htmlResultRelativePath; import static java.lang.String.format; -public class LinkingNoteRenderer implements Renderer{ +public class LinkingNoteRenderer implements Renderer { + + private final Class source; + + public LinkingNoteRenderer(Class source) { + this.source = source; + } @Override public String render(LinkingNote linkingNoteNotes) throws Exception { @@ -20,8 +27,30 @@ public String render(LinkingNote linkingNoteNotes) throws Exception { private Callable1 link() { return new Callable1() { @Override - public String call(Class aClass) throws Exception { - return format("%s", htmlResultFile(outputDirectory(), aClass), wordify(aClass.getSimpleName())); + public String call(Class targetClass) throws Exception { + return format("%s", htmlResultFile(targetClass, source), wordify(targetClass.getSimpleName())); + } + }; + } + + private File htmlResultFile(Class resultClass, Class sourceClass) { + return new File(getRootDirectoryPath(sourceClass) + htmlResultRelativePath(resultClass)); + } + + public String getRootDirectoryPath(Class sourceClass) { + return sequence(htmlResultRelativePath(sourceClass).split("/")) + .map(toParent()) + .toString(""); + } + + private Callable1 toParent() { + return new Callable1() { + @Override + public String call(String s) throws Exception { + if (s.contains(".")) { + return ""; + } + return "../"; } }; } diff --git a/src/com/googlecode/yatspec/rendering/html/HtmlResultRenderer.java b/src/com/googlecode/yatspec/rendering/html/HtmlResultRenderer.java index 570c795f..fd53347d 100644 --- a/src/com/googlecode/yatspec/rendering/html/HtmlResultRenderer.java +++ b/src/com/googlecode/yatspec/rendering/html/HtmlResultRenderer.java @@ -52,7 +52,7 @@ public String render(Result result) throws Exception { group.registerRenderer(instanceOf(ScenarioTableHeader.class), callable(new ScenarioTableHeaderRenderer())); group.registerRenderer(instanceOf(JavaSource.class), callable(new JavaSourceRenderer())); group.registerRenderer(instanceOf(Notes.class), callable(new NotesRenderer())); - group.registerRenderer(instanceOf(LinkingNote.class), callable(new LinkingNoteRenderer())); + group.registerRenderer(instanceOf(LinkingNote.class), callable(new LinkingNoteRenderer(result.getTestClass()))); group.registerRenderer(instanceOf(Content.class), asString()); sequence(customRenderers).fold(group, registerRenderer()); for (Class document : Creator.optionalClass("org.jdom.Document")) { diff --git a/test/com/googlecode/yatspec/junit/LinkingNoteRendererTest.java b/test/com/googlecode/yatspec/junit/LinkingNoteRendererTest.java index 67b75129..0e0359dd 100644 --- a/test/com/googlecode/yatspec/junit/LinkingNoteRendererTest.java +++ b/test/com/googlecode/yatspec/junit/LinkingNoteRendererTest.java @@ -8,7 +8,6 @@ import java.util.List; import static com.googlecode.totallylazy.Sequences.sequence; -import static com.googlecode.yatspec.junit.SpecRunner.outputDirectory; import static com.googlecode.yatspec.parsing.TestParser.parseTestMethods; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; @@ -19,11 +18,11 @@ public class LinkingNoteRendererTest { @LinkingNote(message="Classes specified in the linking note should result in links to the resulted yatspec output eg. %s, %s", links = {String.class, Integer.class}) public void shouldRenderLinkedNotesAsNotesWithLinksToTheYatspecOutputOfTheTestClassesSpecified() throws Exception { assertThat(theRenderedValueOfTheLinkingNoteOfThisMethod(), - is("Classes specified in the linking note should result in links to the resulted yatspec output eg. String, Integer")); + is("Classes specified in the linking note should result in links to the resulted yatspec output eg. String, Integer")); } private String theRenderedValueOfTheLinkingNoteOfThisMethod() throws Exception { final List methods = parseTestMethods(getClass()); - return new LinkingNoteRenderer().render(sequence(sequence(methods).first().getAnnotations()).safeCast(LinkingNote.class).head()); + return new LinkingNoteRenderer(LinkingNoteRendererTest.class).render(sequence(sequence(methods).first().getAnnotations()).safeCast(LinkingNote.class).head()); } }