java - How to mock a class throughout the system using Mockito -


i have method trying test using mockito:

public class miscutil{      public int getvalue(string key){         properties properties = new helper().getproperties() //this method                                                               //i need mock         return properties.get(key)     } 

here test class :

public class miscutiltest{  public void testgetbooleanvalue() {      properties properties = new properties();     properties.setproperty(my_special_int_property, 10);     // mock helper     helper mock = mockito.mock(helper.class);     // mock method getproperties()     mockito.when(mock.getproperties()).thenreturn(properties);      // assert getvalue() method      assert.assertequals(10,miscutil.getvalue(my_special_int_property)); 

however, method doesn't mocked. have pass actual mocked instance miscutil class in order mocking take effect? miscutil class doesn't let me pass helper object it. easy mock particular method of class in jmockit though upper classes may not have access it. possible in mockito?

if trying test behavior of getvalue() method , need provide (mock) objects method needs.

the miscutil class, needs instance of helper object. need pass object via miscutils' constructor (or way), because it's dependency of class.

so it's dependency , don't want test should me mocked, , call real method want test ( miscutil.getvalue(my_special_int_property) ).


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -