commit 43: b4029fbec56f
parent 42: e3def245b8c9
branch: default
[am, ap, pairwithus] New Behaviour: Information now uses MethodNames for method names S02E08
AntonyMarcano
7 months ago

Changed (Δ867 bytes):

Up to file-list src/org/jnarrate/fit/fixture/entityname/Information.java:

@@ -9,34 +9,25 @@ import org.jnarrate.action.PerformableAs
9
9
10
10
public class Information {
11
11
12
  private static final String EVERYTHING_BEFORE_THE_FIRST_QUOTE = "^(.*) \"";
13
  private static final String SOMETHING_INSIDE_QUOTES = "\"(.*)\"";
14
  private String value;
15
  private String methodName;
12
  private static final String BEFORE_THE_FIRST_QUOTE = "^(.*) \"";
13
  private static final String INSIDE_QUOTES = "\"(.*)\"";
14
  private final String value;
15
  private final MethodName methodName;
16
16
17
  public Information(String sentenceFragment) {
18
    methodName = extractMethodNameFrom(sentenceFragment);
19
    value = extractValueFrom(sentenceFragment);
17
  public Information(String fromThisSentenceFragment) {
18
    methodName = new MethodName(theText(BEFORE_THE_FIRST_QUOTE,fromThisSentenceFragment));
19
    value = theText(INSIDE_QUOTES, fromThisSentenceFragment);
20
20
  }
21
22
  private String extractValueFrom(String sentenceFragment) {
23
    Pattern valuePattern = Pattern.compile(SOMETHING_INSIDE_QUOTES);
24
    Matcher matcher = valuePattern.matcher(sentenceFragment);
25
    matcher.find();
26
    return matcher.group(1);
27
  }
28
29
  private String extractMethodNameFrom(String sentenceFragment) {
30
    Pattern valuePattern = Pattern.compile(EVERYTHING_BEFORE_THE_FIRST_QUOTE);
31
    
32
    Matcher matcher = valuePattern.matcher(sentenceFragment);
21
  private String theText(String thisPattern, String fromThisSentenceFragment) {
22
    Pattern valuePattern = Pattern.compile(thisPattern);
23
    Matcher matcher = valuePattern.matcher(fromThisSentenceFragment);
33
24
    matcher.find();
34
25
    return matcher.group(1);
35
26
  }
36
27
37
28
  public <T> PerformableAsA<T> addYourselfToThe(PerformableAsA<T> lookedUpAction) {
38
29
    try {
39
      Method method = lookedUpAction.getClass().getMethod(methodName, String.class);
30
      Method method = lookedUpAction.getClass().getMethod(methodName.toString(), String.class);
40
31
      method.invoke(lookedUpAction, value);
41
32
      return lookedUpAction;
42
33
    }

Up to file-list test/org/jnarrate/fit/fixture/NarrativeFixtureTest.java:

@@ -140,6 +140,7 @@ public class NarrativeFixtureTest {
140
140
    verify(actor).perform(action);
141
141
  }
142
142
143
  @SuppressWarnings("unchecked") // because we're mocking generics
143
144
  @Test
144
145
  public void shouldTellActorToPerformActionWithSomeInformation() throws Exception {
145
146
    String theRole = "some Actor";

Up to file-list test/org/jnarrate/fit/fixture/entityname/InformationShould.java:

@@ -40,7 +40,7 @@ public class InformationShould {
40
40
  
41
41
  @Test
42
42
  public void informTheActionWithADifferentMethod() throws Exception {
43
    String sentenceFragment = "aDifferentMethodName \"a value\"";
43
    String sentenceFragment = "a Different Method Name \"a value\"";
44
44
45
45
    ActionWithAMethodName action = mock(ActionWithAMethodName.class);
46
46
    Information information = new Information(sentenceFragment);

Up to file-list test/org/jnarrate/fit/fixture/entityname/information/ActionWithAMethodName.java:

1
1
package org.jnarrate.fit.fixture.entityname.information;
2
2
3
import org.jnarrate.action.ActorPlayingThe;
4
3
import org.jnarrate.action.DummyRole;
5
import org.jnarrate.action.PerformableAction;
6
4
import org.jnarrate.action.PerformableAsA;
7
5
8
public class ActionWithAMethodName implements PerformableAsA<DummyRole> {
6
public interface ActionWithAMethodName extends PerformableAsA<DummyRole> {
9
7
10
  public PerformableAction toBePerformedBy(ActorPlayingThe<DummyRole> actor) {
11
    throw new UnsupportedOperationException("This method is in a class that is used for testing purposes only");
12
  }
13
14
  public void aMethodName(String aValue) {
15
    throw new UnsupportedOperationException("This method is in a class that is used for testing purposes only");
16
  }
17
18
  public void aDifferentMethodName(String string) {
19
    throw new UnsupportedOperationException("This method is in a class that is used for testing purposes only");
20
  }
8
  void aMethodName(String aValue);
9
  void aDifferentMethodName(String string);
21
10
}

Up to file-list test/org/jnarrate/fit/fixture/expertise/SubjectMatterExpertTest.java:

@@ -37,7 +37,8 @@ public class SubjectMatterExpertTest {
37
37
		assertThat(returnedAction, is(sameInstance((PerformableAsA<ROLE>)action)));
38
38
	}
39
39
	
40
	@Test
40
	@SuppressWarnings("unchecked") // because we're mocking generics
41
  @Test
41
42
  public <ROLE> void shouldTellTheAdditionalInformationToInformTheLookedUpAction() throws Exception {
42
43
	  PerformableAsA<ROLE> lookedUpAction = mock(PerformableAsA.class);
43
44
	  Librarian librarian = mock(Librarian.class);