SourceService implements ISourceService { @Override public List<Source> sortSources(List<Source> sources) { List<Source> sortedList = new ArrayList<>(sources); Collections.sort(sortedList, getSourceComparator().reversed()); return Collections.unmodifiableList(sortedList); }  @Override int count(); @Override Source createSource(String url, String username, String password, Integer maxDownloads); @Override Source getSource(int sourceId); @Override Source getSource(SynchronizerSource synchronizerSource); @Override List<Source> getSource(List<SynchronizerSource> synchronizerSources); @Override boolean updateSource(Source source); @Override boolean deleteSource(Source source); @Override List<Source> list(); @Override List<Source> sortSources(List<Source> sources); @Override Source getBestSource(List<Source> sources);  }
@Test public void sortSource() { Source source0 = EasyMock.createMock(Source.class); source0.setId(0); EasyMock.expect(source0.getBandwidth()).andStubReturn(3L); EasyMock.expect(source0.getId()).andStubReturn(0); Source source1 = EasyMock.createMock(Source.class); source1.setId(1); EasyMock.expect(source1.getBandwidth()).andStubReturn(12L); EasyMock.expect(source1.getId()).andStubReturn(1); Source source2 = EasyMock.createMock(Source.class); source2.setId(2); EasyMock.expect(source2.getBandwidth()).andStubReturn(1L); EasyMock.expect(source2.getId()).andStubReturn(2); Source source3 = EasyMock.createMock(Source.class); source3.setId(3); EasyMock.expect(source3.getBandwidth()).andStubReturn(3L); EasyMock.expect(source3.getId()).andStubReturn(3); Source source4 = EasyMock.createMock(Source.class); source4.setId(4); EasyMock.expect(source4.getBandwidth()).andStubReturn(8L); EasyMock.expect(source4.getId()).andStubReturn(4); Source source5 = EasyMock.createMock(Source.class); source5.setId(5); EasyMock.expect(source5.getBandwidth()).andStubReturn(-1L); EasyMock.expect(source5.getId()).andStubReturn(5); EasyMock.replay(source0, source1, source2, source3, source4, source5); List<Source> sources = Arrays.asList(source0, source1, source2, source3, source4, source5); List<Source> sortedList = service.sortSources(sources); Assert.assertNotNull(sortedList); Assert.assertEquals(sortedList.size(), 6); Assert.assertEquals(sortedList.get(0).getId(), 5); Assert.assertEquals(sortedList.get(1).getId(), 1); Assert.assertEquals(sortedList.get(2).getId(), 4); Assert.assertEquals(sortedList.get(3).getId(), 0); Assert.assertEquals(sortedList.get(4).getId(), 3); Assert.assertEquals(sortedList.get(5).getId(), 2); }