Skip to content

Commit

Permalink
Merge pull request #25 from theangrydev/master
Browse files Browse the repository at this point in the history
Use relative paths for @LinkingNote so that the paths work on CI
  • Loading branch information
danielbodart committed Nov 5, 2015
2 parents a174567 + 6a9f696 commit e485ed3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
41 changes: 35 additions & 6 deletions src/com/googlecode/yatspec/rendering/LinkingNoteRenderer.java
Original file line number Diff line number Diff line change
@@ -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<LinkingNote>{
public class LinkingNoteRenderer implements Renderer<LinkingNote> {

private final Class<?> source;

public LinkingNoteRenderer(Class<?> source) {
this.source = source;
}

@Override
public String render(LinkingNote linkingNoteNotes) throws Exception {
Expand All @@ -20,8 +27,30 @@ public String render(LinkingNote linkingNoteNotes) throws Exception {
private Callable1<Class, String> link() {
return new Callable1<Class, String>() {
@Override
public String call(Class aClass) throws Exception {
return format("<a href='%s'>%s</a>", htmlResultFile(outputDirectory(), aClass), wordify(aClass.getSimpleName()));
public String call(Class targetClass) throws Exception {
return format("<a href='%s'>%s</a>", 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<? super String, String> toParent() {
return new Callable1<String, String>() {
@Override
public String call(String s) throws Exception {
if (s.contains(".")) {
return "";
}
return "../";
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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. <a href='" + outputDirectory() +"/java/lang/String.html'>String</a>, <a href='" + outputDirectory() + "/java/lang/Integer.html'>Integer</a>"));
is("Classes specified in the linking note should result in links to the resulted yatspec output eg. <a href='../../../../java/lang/String.html'>String</a>, <a href='../../../../java/lang/Integer.html'>Integer</a>"));
}

private String theRenderedValueOfTheLinkingNoteOfThisMethod() throws Exception {
final List<TestMethod> 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());
}
}

0 comments on commit e485ed3

Please sign in to comment.