Note that there are some explanatory texts on larger screens.

plurals
  1. POMockito code during @Before annoted method solution
    text
    copied!<p>i'm new on using Mockito framework (and Behavior/Test Driven Development) and using to help me code some things;</p> <p>I´m coding my own Java library for xml to create graphic things and i tried first verify some behaviours: (<code>MockitoAnnotations.initMocks(Class)</code> is used in <code>BaseTestClass</code>):</p> <pre><code>public class GeneralXml extends BaseTestClass { private static final String TAG = "General XML"; @Mock(name="xml") private XmlGraphics mockXML; @Before public void setUp() throws Exception{ //stub method parseDimension when(mockXML.parseDimension(anyString())) .thenReturn(500); // stub method parsePosition: 500 X 500 X 500 is an // arbitrary dimension of window when(mockXML.parsePosition(anyString())) .thenReturn( new Random().nextFloat() * mockXML.parseDimension(Xml.WIDTH), new Random().nextFloat() * mockXML.parseDimension(Xml.HEIGHT), new Random().nextFloat() * mockXML.parseDimension(Xml.DEPHT)); // Now Colors must have betwwen 0 and 255 // (RGB color) when(mockXML.parseColorComponent(anyString())) .thenReturn( new Random().nextInt(256), new Random().nextInt(256), new Random().nextInt(256)); } </code></pre> <p>But I receive error in all subsequent verifications, like:</p> <pre><code>@Test public void mockPosition() { Log.d(TAG, "mock", "x = "+mockXML.parsePosition(Xml.X)); Log.d(TAG, "mock", "y = "+mockXML.parsePosition(Xml.Y)); Log.d(TAG, "mock", "z = "+mockXML.parsePosition(Xml.Z)); verify(mockXML, times(3)).parsePosition(anyString()); } </code></pre> <p>I think that my error is in: </p> <pre><code> when(mockXML.parsePosition(anyString())) .thenReturn( new Random().nextFloat() * mockXML.parseDimension(Xml.WIDTH), new Random().nextFloat() * mockXML.parseDimension(Xml.HEIGHT), new Random().nextFloat() * mockXML.parseDimension(Xml.DEPHT)); </code></pre> <p>This is not a valid code? or I misunderstanding something? Thanks for any help</p>
 

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