java - mockito - how to mock different behaviors for different arguments -


i want simple mock behave 1 way when called given argument, , when called else.

i've tried variations on this:

when(this.mockwebelement.findelement(not(eq(by.xpath("./td[1]"))))).thenreturn(this.mockwebelement); when(this.mockwebelement.gettext()).thenreturn("somestring");  when(this.mockwebelement.findelement(by.xpath("./td[1]"))).thenreturn(datemockelement); when(datemockelement.gettext()).thenreturn("8/1/2014", "7/1/2014", "6/1/2014", "5/1/2014"); 

the call gettext(by.xpath("./td[1]")) returns "somestring". i've tried and(eq(any(by.class)), not(eq(by.xpath("./td[1]"))).

using code basis, following test passed me:

@before public void setup() throws exception {     mockitoannotations.initmocks(this); }      @mock private webelement mockwebelement;     @mock private webelement datemockelement;      @test     public void testx() throws exception {         when(this.mockwebelement.findelement(not(eq(by.xpath("./td[1]"))))).thenreturn(this.mockwebelement);         when(this.mockwebelement.gettext()).thenreturn("somestring");          when(this.mockwebelement.findelement(by.xpath("./td[1]"))).thenreturn(datemockelement);         when(datemockelement.gettext()).thenreturn("8/1/2014", "7/1/2014", "6/1/2014", "5/1/2014");          webelement w = mockwebelement.findelement(by.xpath("./td[1]"));         string x= w.gettext();         assertequals("8/1/2014", x);     } 

since haven't shown rest of test, i'm assuming error in rest of plumbing of actual test setup , execution.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -