Skip to content

Commit

Permalink
Tidying up test to all fit in one short method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Aug 2, 2013
1 parent 65376e1 commit fc8a1a7
Showing 1 changed file with 9 additions and 35 deletions.
44 changes: 9 additions & 35 deletions src/test/java/hudson/plugins/mercurial/MercurialSCMTest.java
Expand Up @@ -35,8 +35,6 @@

public class MercurialSCMTest {

public static final String EXPECTED_SHORT_ID = "123456789012";

@Test public void parseStatus() throws Exception {
assertEquals(new HashSet<String>(Arrays.asList("whatever", "added", "mo-re", "whatever-c", "initial", "more")), MercurialSCM.parseStatus(
"M whatever\n"
Expand All @@ -50,40 +48,16 @@ public class MercurialSCMTest {
}

@Test public void buildEnvVarsSetsShortId() throws IOException {
Map < String, String > actualEnvironment = new HashMap<String, String>();

createMercurialSCM().buildEnvVarsFromActionable(createActionable(), actualEnvironment);

Map<String,String> actualEnvironment = new HashMap<String,String>();
final String EXPECTED_SHORT_ID = "123456789012";
new MercurialSCM("","","", "", "", null, true).buildEnvVarsFromActionable(new Actionable() {
@Override public List<Action> getActions() {
return Collections.<Action>singletonList(new MercurialTagAction(EXPECTED_SHORT_ID + "1627e63489b4096a8858e559a456", "rev", null));
}
@Override public String getDisplayName() {return null;}
@Override public String getSearchUrl() {return null;}
}, actualEnvironment);
assertEquals(EXPECTED_SHORT_ID, actualEnvironment.get("MERCURIAL_REVISION_SHORT"));
}

private MercurialSCM createMercurialSCM() {
return new MercurialSCM("","","", "", "", null, true);
}

private Actionable createActionable() {
List<Action> expectedActions = Arrays.asList((Action) new MercurialTagAction(EXPECTED_SHORT_ID + "1627e63489b4096a8858e559a456", "rev", null));
return new ActionableTestDouble(expectedActions);
}

private class ActionableTestDouble extends Actionable {
private List<Action> expectedActions = new ArrayList<Action>();

public ActionableTestDouble(List<Action> expectedActions) {
this.expectedActions = expectedActions;
}

public String getDisplayName() {
throw new RuntimeException();
}

public String getSearchUrl() {
throw new RuntimeException();
}

@Override
public synchronized List<Action> getActions() {
return expectedActions;
}
}
}

0 comments on commit fc8a1a7

Please sign in to comment.