java - Unit testing a fluent interface with Mockito -


i want mock dao interface used in builder pattern shown below. when run test below passes indicating mock object never called. doing wrong?

public class dbcontent {     ...      public static class builder {          dao dao = new dao();         ...          public builder callinsert() {             ...             long latest = dao.insert();             ...         }     }     ... }  @runwith(mockitojunitrunner.class) public class dbcontenttest {      @mock     dao dao;      @test     public void test() {         when(dao.insert()).thenreturn(1111l);         dbcontent db = dbcontent.db()                 .callinsert()                 .callinsert()                 .callinsert()                 .build();         verifyzerointeractions(dao);     } } 

use powermockito instead. there can define whenever have call constructor of dao, return mocked object instead of returning actual dao object.
please refer this learn how use powermockito.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -