From your description of the expected behavior, this seems like a pretty solid way of unit test method. Under the “true Mockito way,” I suggest that you want something like:
Set mockBSet = mock(Set.class); stub(mockBSet.size()).toReturn(2); A testObjectA = new A(mockBSet); Assert.assertEquals(testObjectA.getSomethingAmount(), 2);
This assumes that initializing the Set and test objects does not have any side effects that you want the test to take into account. (For example, it always adds some default "somethings"). In this case, you can also ignore stubbing and claim that the tested method returns a value equal to the size of the set.
source share