-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from pityq/master
add LinkingNote annotation
- Loading branch information
Showing
5 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.googlecode.yatspec.junit; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.METHOD, ElementType.TYPE}) | ||
@YatspecAnnotation | ||
public @interface LinkingNote { | ||
String message(); | ||
Class[] links(); | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/com/googlecode/yatspec/rendering/LinkingNoteRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.googlecode.yatspec.rendering; | ||
|
||
import com.googlecode.totallylazy.Callable1; | ||
import com.googlecode.totallylazy.Sequence; | ||
import com.googlecode.yatspec.junit.LinkingNote; | ||
|
||
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 java.lang.String.format; | ||
|
||
public class LinkingNoteRenderer implements Renderer<LinkingNote>{ | ||
|
||
@Override | ||
public String render(LinkingNote linkingNoteNotes) throws Exception { | ||
return format(linkingNoteNotes.message(), (Object[])sequence(linkingNoteNotes.links()).map(link()).toArray(String.class)); | ||
} | ||
|
||
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())); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/com/googlecode/yatspec/junit/LinkingNoteRendererTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.googlecode.yatspec.junit; | ||
|
||
import com.googlecode.yatspec.rendering.LinkingNoteRenderer; | ||
import com.googlecode.yatspec.state.TestMethod; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
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; | ||
|
||
@RunWith(SpecRunner.class) | ||
public class LinkingNoteRendererTest { | ||
@Test | ||
@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>")); | ||
} | ||
|
||
private String theRenderedValueOfTheLinkingNoteOfThisMethod() throws Exception { | ||
final List<TestMethod> methods = parseTestMethods(getClass()); | ||
return new LinkingNoteRenderer().render(sequence(sequence(methods).first().getAnnotations()).safeCast(LinkingNote.class).head()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters