Thanks Jörg,

This is kind of where I am at with it now, but actually I declare a
constructor to pass in the mocked domain service objects needed.

Re 'cascades of objects being created being a good or bad thing', this
seems to me a product of encapsulation, hence a product of OO/DDD approach,
so good if the promise of maintainability holds true.

To use a mocked domain services to test seems to me more an aspect of
design than testing per se, but I am now trying that approach
retrospectively.

On Sat, Oct 10, 2015 at 1:39 AM, Rade, Joerg / Kuehne + Nagel / Ham GI-PS <
[email protected]> wrote:

> Hi
>
> Stephen Cameron wrote:
>
> > The sequence of calls on the mock container to create the first object
> (newTransientInstance,
> > persistIfNotAlready, flush), works fine but if that new object in turn
> creates more new objects,
> > then no, as they don't know anything about the mock, you've injected
> that dependancy into the
> > first one only. In my case there is a cascade of object creation
> newParticipant() may trigger
> > newParticipation() and newPerson(). So all I can do is create a test for
> each of these methods
> > (of domain services) individually and hope that it all works in
> combination in an integration
> > test, which is reasonable I guess.
> >
> > But my point is that the thing to mock is the DI container. The class
> DomainObjectContainer
> > isn't actually the DI 'container,' but a proxy, when running a Junit
> test there is no true
> > container, but there is its proxy which we mock, its a subtle
> distinction.
>
> My application has a cascade of create methods as well (which may be a
> good idea or not)
> and I was puzzled how to write unit.
>
> I ended up 'injecting' referenced repositories/factories by hand in
> setUp():
>
> [...]
> public class RuntimeEnvironmentsTest_create {
>
>     @Rule
>     public JUnitRuleMockery2 context =
> JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
>
>     @Mock
>     private DomainObjectContainer mockContainer;
>     @Mock
>     private Hosts hosts;
>     @Mock
>     private Releases releases;
>     @Mock
>     private Properties properties;
>     @Mock
>     public Stages stages;
>
>     private RuntimeEnvironments cut; // ClassUnderTest
>
>     @Before
>     public void setUp() throws Exception {
>         cut = new RuntimeEnvironments();
>         cut.setContainer(mockContainer);
>         cut.hosts = hosts;
>         cut.releases = releases;
>         cut.properties = properties;
>         cut.stages = stages;
>     }
> [...]
> }
>
> Expectations for method calls on the mocked repositories/factories have to
> be created.
>
> HTH
> Jörg
>
> Kühne + Nagel (AG & Co.) KG
> Rechtsform: Kommanditgesellschaft, Bremen HRA 21928, USt-IdNr.: DE
> 812773878.
> Geschäftsleitung Kühne + Nagel (AG & Co.) KG: Reiner Heiken (Vors.), Dirk
> Blesius, Martin Brinkmann, Matthias Heimbach, Jan-Hendrik Köstergarten,
> Nicholas Minde, Lars Wedel, Jens Wollesen.
> Persönlich haftende Gesellschafterin: Kühne & Nagel A.G., Rechtsform:
> Aktiengesellschaft nach luxemburgischem Recht, HR-Nr.: B 18745,
> Geschäftsführendes Verwaltungsratsmitglied: Karl Gernandt.
> Geschäftsleitung Region Westeuropa: Yngve Ruud (Vors.), Richard Huhn,
> Björn Johansson, Jan Kunze, Bruno Mang, Stefan Paul, Holger Ketz, Dominic
> Edmonds.
>
> Wir arbeiten ausschließlich auf Grundlage der Allgemeinen Deutschen
> Spediteursbedingungen (ADSp), jeweils neuester Fassung. Wir verweisen
> insbesondere auf die vom Gesetz abweichenden Haftungsbeschränkungen von
> Ziffer 23 und 24 ADSp. Den vollständigen Text der ADSp übersenden wir Ihnen
> gerne auf Anfrage und können Sie auch unter http://www.kuehne-nagel.com
> einsehen. Ergänzend wird vereinbart, dass (1) Ziffer 27 ADSp im Rahmen
> internationaler Übereinkommen weder unsere Haftung noch die Zurechnung des
> Verschuldens von Leuten und sonstigen Dritten zu Gunsten des Auftraggebers
> erweitert, und (2) wir in den im deutschen Seehandelsrecht aufgeführten
> Fällen des nautischen Verschuldens oder Feuer an Bord nur für eigenes
> Verschulden und (3) im Sinne der CMNI genannten Voraussetzungen nicht für
> nautisches Verschulden, Feuer an Bord oder Mängel des Schiffes haften.
>

Reply via email to