Note that there are some explanatory texts on larger screens.

plurals
  1. POMockito is giving infinite while loops and finite for loops on the same NavigationSet
    primarykey
    data
    text
    <ul> <li>I am using <strong>Mockito</strong> in a <strong>JUnit test</strong>. I mocked a <code>NavigableSet</code>.</li> <li>In my unit test at some point I need to loop into the objects contained in this <code>NavigableSet</code>.</li> <li>I planned this <code>NavigableSet</code>, for testing purposes, to contain only 1 object.</li> </ul> <p>The following is the code I used with Mockito to create the mock object:</p> <pre><code>NavigableSet&lt;ObjectToProcess&gt; newMockedSet = new TreeSet&lt;ObjectToProcess&gt;(); ObjectToProcess mockedInnerObject = new ObjectToProcess(); // initialization of this object newMockedSet.add(mockedInnerObject); // I just added the only 1 object contained in the NavigableSet Mockito.when(getSetOfObjectToProcess()).thenReturn(newMockedSet); </code></pre> <p>Why the following <code>while</code> loop is giving an infinite loop with a <code>NavigableSet</code> containing only 1 object?</p> <pre><code>NavigableSet&lt;ObjectToProcess&gt; anotherSetOfObjects = getSetOfObjectToProcess(); // retrieving the mocked object while (anotherSetOfObjects.iterator().hasNext()) { ObjectToProcess thisPaymentDemand = anotherSetOfObjects.iterator().next(); // do stuff } </code></pre> <p>Why the following <code>for</code> loop is behaving as expected looping only once? </p> <pre><code>NavigableSet&lt;ObjectToProcess&gt; anotherSetOfObjects = getSetOfObjectToProcess(); // retrieving the mocked object for (ObjectToProcess thisMockedInnerObject : anotherSetOfObjects) { ObjectToProcess thisPaymentDemand = thisMockedInnerObject; // do stuff } </code></pre>
    singulars
    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.
 

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