Closed GoogleCodeExporter closed 8 years ago
For documentation, this patch will allow to write tests like that
@RunWith(MockitoJUnitRunner.class)
public class TheTest {
@InjectMocks private TheTested tested;
@Mock private Map mapToBeInjected;
@Mock private List listToBeInjected;
@Test
public void testSomeBehaviour() {}
}
while in the present version, the @InjectMocks field must be initialized.
As for the "mutable safe API" of your tested class, it means you can actually
write something like. So you don't break the encapsulation and the mutability
of your object.
For example following the Joshua Bloch builder style:
public class TheTested {
private Map map;
private List list;
private TheTested() {} // for instanciation in mockito (or other frameworks such as hibernate, depending on your configuration)
private TheTested(Map map, List list) { ... }
public void someBehaviour() { ... }
public void someOtherBehaviour() { ... }
public static Builder builder() { return new Builder(); }
public Builder {
private Map map;
private List list;
public Builder withThatMap(Map str) { ... }
public Builder withThatList(List list) { ... }
public TheTested build() { return new TheTested(map, list); }
}
}
Original comment by brice.du...@gmail.com
on 12 Aug 2010 at 9:29
Hey,
Wanted to install the patch but it seems FieldInitializer is missing. Wanna
update the patch?
Cheers :)
Szczepan
Original comment by szcze...@gmail.com
on 13 Aug 2010 at 11:26
Ouch, indeed.
I'm trying IntelliJ right now, and I missed the new classes.
Well here's the fixed patch.
Sorry ;)
Brice
Original comment by brice.du...@gmail.com
on 13 Aug 2010 at 5:27
Attachments:
Hello back,
I wanted to try the Mercurial clones, but google got only server errors for me.
Anyway here's an updated patch, with a few more unit test, and it also allow
mockito to instantiate spies if the type have a no-arg constructor.
Original comment by brice.du...@gmail.com
on 17 Oct 2010 at 6:30
Attachments:
Brice I updated the title of this issue - please correct me if it's not right
Original comment by szcze...@gmail.com
on 18 Oct 2010 at 12:13
Original comment by brice.du...@gmail.com
on 18 Oct 2010 at 12:32
Original comment by brice.du...@gmail.com
on 18 Oct 2010 at 5:44
Original comment by szcze...@gmail.com
on 29 Oct 2010 at 7:50
Original comment by szcze...@gmail.com
on 3 Jul 2011 at 12:43
Original comment by brice.du...@gmail.com
on 3 Sep 2012 at 10:00
Original issue reported on code.google.com by
brice.du...@gmail.com
on 7 Aug 2010 at 5:36Attachments: