Skip to content

Loading…

Update testsupport/src/main/java/com/danhaywood/testsupport/jmock/JUnitR... #1

Merged
merged 1 commit into from

2 participants

@witoldsz

With this change we can avoid writing extra casting:

@ClassUnderTest
private Collaborating collaborating;

//before ---------------------------
public void setUp() throws Exception {
    collaborating = (Collaborating) context.getClassUnderTest();
}

//after ---------------------------
public void setUp() throws Exception {
    collaborating = context.getClassUnderTest();
}

source: http://java.dzone.com/articles/mockito-automocking-and

@danhaywood
Owner

Nice. And I feel kinda stupid that I didn't write it this way in the first place. Will merge.

@danhaywood danhaywood merged commit d9ef9f2 into danhaywood:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 24, 2012
  1. @witoldsz
This page is out of date. Refresh to see the latest.
View
4 testsupport/src/main/java/com/danhaywood/testsupport/jmock/JUnitRuleMockery2.java
@@ -173,11 +173,11 @@ private void assertOnlyOneJMockContextIn(final List<Field> allFields) {
}
- public Object getClassUnderTest() {
+ public <T> T getClassUnderTest() {
if(cutType == null) {
throw new IllegalStateException("No field annotated @ClassUnderTest was found");
}
- return container.getComponent(cutType);
+ return (T) container.getComponent(cutType);
}
Something went wrong with that request. Please try again.