EmulatorProviderImpl implements EmulatorProvider { @Override public List<Emulator> getEmulators(Resource resource) { List<Emulator> emulators = new ArrayList<>(); for (EmulatorGroup group : getEmulatorGroups(resource)) { emulators.addAll(group.getEmulators()); } return emulators; }  @Override boolean handles(Resource resource); @Override List<Emulator> getEmulators(Resource resource); @Override List<EmulatorGroup> getEmulatorGroups(Resource resource);  }
@Test void testGetEmulators() { Resource resource = mock(Resource.class); Page page = mock(Page.class); when(resource.adaptTo(Page.class)).thenReturn(page); DeviceGroupListMock deviceGroupList = new DeviceGroupListMock(); when(page.adaptTo(DeviceGroupList.class)).thenReturn(deviceGroupList); DeviceGroup deviceGroup1 = mock(DeviceGroup.class); Emulator emulator1 = mock(Emulator.class); Emulator emulator2 = mock(Emulator.class); deviceGroupList.add(deviceGroup1); when(deviceGroup1.getEmulators()).thenReturn(ImmutableList.of(emulator1, emulator2)); DeviceGroup deviceGroup2 = mock(DeviceGroup.class); Emulator emulator3 = mock(Emulator.class); when(deviceGroup2.getEmulators()).thenReturn(ImmutableList.of(emulator3)); deviceGroupList.add(deviceGroup2); List<Emulator> emulators = underTest.getEmulators(resource); assertEquals(3, emulators.size()); assertTrue(emulators.contains(emulator1)); assertTrue(emulators.contains(emulator2)); assertTrue(emulators.contains(emulator3)); }