I am writing (junit) unit tests for a class that implements an open interface using methods such as:
public Set<Setting> getUserSettings(); public Set<Setting> getOrganizationSettings(); public Set<Setting> getDefaults(); public Set<Setting> getAllSettings();
Methods for getting settings from a certain level make IO from different places to get their results. getAllSettings () Returns a single set of all settings at all levels, with the upper level having preference (i.e. if the parameter exists at the default level and at the user level, the setting at the user level will be used.
I already wrote unit tests for getUserSettings (), getOrganizationSettings (), getDefaults (), mocking I / O with Mocked objects.
The implementation for getAllSettings () looks something like this:
public Set<Setting> getAllSettings(){ Set<Setting> defaults = getUserSettings(); Set<Setting> custom = getOrganizationSettings(); Set<Setting> undefined = getDefaults(); //perform some sorting and business logic //return fully sorted set }
My question is how to unit test getAllSettings () method. Can I use mocks (using easymock / powermock) for all downstream resource calls that use user / organization / defaultSettings methods? It seems like it will be a cleaner / better / easier way to do this.
source share