Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's unfortunate that you're using <code>getResultState()</code> to create the <code>ResultState</code> object, itself, which is really your blocker. Consider refactoring into the following interface:</p> <pre><code>protected ResultState initResultState ( ) { this.resultState = new ResultState(); // Initialization Logic... return this.resultState; } // END initResultState public ResultState getResultState ( ) { if ( this.resultState === null ) { return this.initResultState(); } return this.resultState; } // END getResultState() </code></pre> <p>From this position, it's easier to test your getter method. Define a descendant class that returns a known <code>ResultState</code> Stub for <code>initResultState()</code> that can be interrogated, ie:</p> <pre><code>/** * The test fixutre's initResultState() method merely returns a simple Stub of * the ResultState object, which can be more easily interrogated. */ public ResultState initResultState ( ) { return new Stub_ResultState(); } // END initResultState </code></pre> <p>That still leaves you with the protected <code>initResultState()</code>, of course. Consider the following refactoring:</p> <pre><code>protected ResultState initResultState ( ResultState newResultState ) { this.resultState = newResultState; // Initialization Logic... return this.resultState; } // END initResultState public ResultState getResultState ( ) { if ( this.resultState === null ) { return this.initResultState( new ResultState() ); } return this.resultState; } // END getResultState </code></pre> <p>This permits you to override the <code>getResultState()</code> method in a descendant class such that you can pass another <code>ResultState</code> Stub object to be manipulated and interrogated afterward, for example:</p> <pre><code>/** * The test fixture's getResultState() method always acts as a passthrough for * initResultState(), which is protected, so that the output of the protected * method can be interrogated. */ public ResultState getResultState ( ) { return this.initResultState( new Stub_ResultState() ); } // END getResultState </code></pre> <p>From this position, you need <em>two</em> test fixtures: one that overrides the behavior of <code>initResultState()</code> to test the functionality of the getters; another that overrides the behavior of <code>getResultState()</code> to test the behavior of <code>initResultState()</code>. Both use an instance of the <code>Stub_ResultState</code> class, which is necessarily a descendant of the <code>ResultState</code> class but provides public access to the internal values of its parent object for interrogation in unit tests.</p> <p>I hope that makes sense, but feel free to ask for clarifications.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload