testingreflections / NarrativeFixture (http://pairwith.us/current-project.html)
New Narrative Fixture as featured in http://pairwith.us
$ hg clone http://bitbucket.org/testingreflections/narrativefixture/
| commit 23: | 9770bed86cba |
| parent 22: | ac644b1014e3 |
| branch: | default |
9 months ago
Changed (Δ758 bytes):
src/org/jnarrate/fit/fixture/expertise/CastingAgent.java (1 lines added, 0 lines removed)
src/org/jnarrate/fit/fixture/expertise/ClassNameTranslator.java
src/org/jnarrate/fit/fixture/expertise/SubjectMatterExpert.java (4 lines added, 10 lines removed)
test/org/jnarrate/action/DummyAction.java (2 lines added, 2 lines removed)
test/org/jnarrate/fit/fixture/expertise/ClassNameTranslatorTest.java
test/org/jnarrate/fit/fixture/expertise/SubjectMatterExpertTest.java (28 lines added, 31 lines removed)
test/org/jnarrate/question/SomeOtherQuestion.java
Up to file-list src/org/jnarrate/fit/fixture/expertise/CastingAgent.java:
| … | … | @@ -6,6 +6,7 @@ import java.util.List; |
6 |
6 |
import org.jnarrate.action.ActorPlayingThe; |
7 |
7 |
import org.jnarrate.fit.fixture.expertise.apology.CastingApology; |
8 |
8 |
import org.jnarrate.fit.fixture.expertise.misuse.TooManyChoicesComplaint; |
9 |
import org.jnarrate.stuff.ClassNameTranslator; |
|
9 |
10 |
|
10 |
11 |
public class CastingAgent { |
11 |
12 |
Up to file-list src/org/jnarrate/fit/fixture/expertise/SubjectMatterExpert.java:
| … | … | @@ -4,25 +4,20 @@ import org.jnarrate.action.PerformableAs |
4 |
4 |
import org.jnarrate.expertise.Librarian; |
5 |
5 |
import org.jnarrate.fit.fixture.expertise.misuse.NotAnActionComplaint; |
6 |
6 |
import org.jnarrate.question.AnswerableBy; |
7 |
import org.jnarrate.stuff.ClassName; |
|
7 |
8 |
|
8 |
9 |
public class SubjectMatterExpert { |
9 |
10 |
|
10 |
11 |
private static final String LOCATION_BASE = "org.jnarrate."; |
11 |
12 |
private static final String PERFORM = "action"; |
12 |
13 |
private static final String ASK = "question"; |
13 |
private final ClassNameTranslator translator; |
|
14 |
14 |
private final Librarian librarian; |
15 |
15 |
|
16 |
16 |
public SubjectMatterExpert() { |
17 |
this(new |
|
17 |
this(new Librarian()); |
|
18 |
18 |
} |
19 |
19 |
|
20 |
public SubjectMatterExpert(ClassNameTranslator translator) { |
|
21 |
this(translator, new Librarian()); |
|
22 |
} |
|
23 |
||
24 |
public SubjectMatterExpert(ClassNameTranslator translator, Librarian librarian) { |
|
25 |
this.translator = translator; |
|
20 |
public SubjectMatterExpert(Librarian librarian) { |
|
26 |
21 |
this.librarian = librarian; |
27 |
22 |
} |
28 |
23 |
|
| … | … | @@ -41,8 +36,7 @@ public class SubjectMatterExpert { |
41 |
36 |
} |
42 |
37 |
|
43 |
38 |
private <T> T howTo(String doSomething, String thisAction) { |
44 |
String action = translator.howDoISay(thisAction); |
|
45 |
39 |
String fromThisLocation = LOCATION_BASE + doSomething; |
46 |
return librarian.findMeA( |
|
40 |
return librarian.findMeA(new ClassName(thisAction), fromThisLocation); |
|
47 |
41 |
} |
48 |
42 |
} |
Up to file-list test/org/jnarrate/action/DummyAction.java:
1 |
1 |
package org.jnarrate.action; |
2 |
2 |
|
3 |
public class DummyAction |
|
3 |
public class DummyAction implements PerformableAsA<DummyRole> { |
|
4 |
4 |
|
5 |
public PerformableAction toBePerformedBy(ActorPlayingThe< |
|
5 |
public PerformableAction toBePerformedBy(ActorPlayingThe<DummyRole> actor) { |
|
6 |
6 |
throw new UnsupportedOperationException("TODO: Implement This Method"); |
7 |
7 |
} |
8 |
8 |
Up to file-list test/org/jnarrate/fit/fixture/expertise/SubjectMatterExpertTest.java:
| … | … | @@ -2,42 +2,45 @@ package org.jnarrate.fit.fixture.experti |
2 |
2 |
|
3 |
3 |
import static org.hamcrest.CoreMatchers.instanceOf; |
4 |
4 |
import static org.hamcrest.CoreMatchers.is; |
5 |
import static org.hamcrest.CoreMatchers.sameInstance; |
|
5 |
6 |
import static org.junit.Assert.assertThat; |
7 |
import static org.mockito.Mockito.mock; |
|
8 |
import static org.mockito.Mockito.when; |
|
6 |
9 |
|
7 |
import org.jnarrate.action.D |
|
10 |
import org.jnarrate.action.DoSomethingThatIsntAnAction; |
|
8 |
11 |
import org.jnarrate.action.DummyAction; |
9 |
12 |
import org.jnarrate.action.DummyRole; |
10 |
13 |
import org.jnarrate.action.PerformableAsA; |
14 |
import org.jnarrate.expertise.Librarian; |
|
11 |
15 |
import org.jnarrate.fit.fixture.expertise.misuse.NotAnActionComplaint; |
12 |
16 |
import org.jnarrate.question.AnswerableBy; |
13 |
import org.jnarrate.question.SomeOtherQuestion; |
|
14 |
17 |
import org.jnarrate.question.SomeQuestion; |
18 |
import org.jnarrate.stuff.ClassName; |
|
15 |
19 |
import org.junit.Test; |
16 |
20 |
|
17 |
21 |
public class SubjectMatterExpertTest { |
18 |
22 |
|
19 |
@Test |
|
20 |
public void shouldTellUsHowToDoSomething() throws Exception { |
|
21 |
|
|
23 |
@SuppressWarnings("unchecked") // because we control the returned result |
|
24 |
@Test |
|
25 |
public <ROLE> void shouldTellTheLibrarianToRetrieveTheActionBasedOnTheTranslatedActionName() throws Exception { |
|
26 |
Librarian librarian = mock(Librarian.class); |
|
27 |
DummyAction action = new DummyAction(); |
|
28 |
SubjectMatterExpert sme = new SubjectMatterExpert(librarian); |
|
29 |
when(librarian.findMeA(new ClassName("Dummy Action"), "org.jnarrate.action")).thenReturn(action); |
|
22 |
30 |
|
23 |
PerformableAsA< |
|
31 |
PerformableAsA<ROLE> returnedAction = sme.howDoI("Dummy Action"); |
|
24 |
32 |
|
25 |
assertThat( |
|
33 |
assertThat(returnedAction, is(sameInstance((PerformableAsA<ROLE>)action))); |
|
26 |
34 |
} |
27 |
||
28 |
@Test |
|
29 |
public void shouldTellUsHowToDoSomethingDifferent() throws Exception { |
|
30 |
SubjectMatterExpert sme = new SubjectMatterExpert(); |
|
31 |
||
32 |
PerformableAsA<?> action = sme.howDoI("Different Dummy Action"); |
|
33 |
||
34 |
assertThat(action, is(instanceOf(DifferentDummyAction.class))); |
|
35 |
} |
|
36 |
||
35 |
||
37 |
36 |
@Test |
38 |
37 |
public void shouldTakeExceptionWhenTheSubjectMatterIsntAnAction() throws Exception { |
39 |
SubjectMatterExpert sme = new SubjectMatterExpert(); |
|
40 |
Exception thrown = null; |
|
38 |
Librarian librarian = mock(Librarian.class); |
|
39 |
DoSomethingThatIsntAnAction action = new DoSomethingThatIsntAnAction(); |
|
40 |
SubjectMatterExpert sme = new SubjectMatterExpert(librarian); |
|
41 |
when(librarian.findMeA(new ClassName("do something that isnt an action"), "org.jnarrate.action")).thenReturn(action); |
|
42 |
||
43 |
Exception thrown = null; |
|
41 |
44 |
|
42 |
45 |
try { |
43 |
46 |
sme.howDoI("do something that isnt an action"); |
| … | … | @@ -51,19 +54,13 @@ public class SubjectMatterExpertTest { |
51 |
54 |
|
52 |
55 |
@Test |
53 |
56 |
public void shouldGiveUsAQuestion() throws Exception { |
54 |
|
|
57 |
Librarian librarian = mock(Librarian.class); |
|
58 |
SomeQuestion question = new SomeQuestion(); |
|
59 |
SubjectMatterExpert sme = new SubjectMatterExpert(librarian); |
|
60 |
when(librarian.findMeA(new ClassName("some Question"), "org.jnarrate.question")).thenReturn(question); |
|
55 |
61 |
|
56 |
AnswerableBy<DummyRole, String> |
|
62 |
AnswerableBy<DummyRole, String> returnedQuestion = sme.howDoIAnswer("Some Question"); |
|
57 |
63 |
|
58 |
assertThat(question, is(instanceOf(SomeQuestion.class))); |
|
59 |
} |
|
60 |
||
61 |
@Test |
|
62 |
public void shouldGiveUsADifferentQuestion() throws Exception { |
|
63 |
SubjectMatterExpert sme = new SubjectMatterExpert(); |
|
64 |
||
65 |
AnswerableBy<DummyRole, String> question = sme.howDoIAnswer("Some Other Question"); |
|
66 |
||
67 |
assertThat(question, is(instanceOf(SomeOtherQuestion.class))); |
|
64 |
assertThat(returnedQuestion, is(sameInstance((AnswerableBy<DummyRole, String>)question))); |
|
68 |
65 |
} |
69 |
66 |
} |
