Use more generic collection instead of list

This commit is contained in:
René Pfeuffer
2018-10-11 09:55:47 +02:00
parent e296812457
commit b4c854ee99
4 changed files with 80 additions and 164 deletions

View File

@@ -33,14 +33,12 @@
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import sonia.scm.repository.BrowserResult;
import sonia.scm.repository.FileObject;
import java.io.IOException;
import java.util.List;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -48,8 +46,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra
@@ -68,7 +64,7 @@ public class HgBrowseCommandTest extends AbstractHgCommandTestBase {
@Test
public void testBrowse() throws IOException {
List<FileObject> foList = getRootFromTip(new BrowseCommandRequest());
Collection<FileObject> foList = getRootFromTip(new BrowseCommandRequest());
FileObject a = getFileObject(foList, "a.txt");
FileObject c = getFileObject(foList, "c");
@@ -96,7 +92,7 @@ public class HgBrowseCommandTest extends AbstractHgCommandTestBase {
FileObject c = result.getFile();
assertEquals("c", c.getName());
List<FileObject> foList = c.getChildren();
Collection<FileObject> foList = c.getChildren();
assertNotNull(foList);
assertFalse(foList.isEmpty());
@@ -139,7 +135,7 @@ public class HgBrowseCommandTest extends AbstractHgCommandTestBase {
request.setDisableLastCommit(true);
List<FileObject> foList = getRootFromTip(request);
Collection<FileObject> foList = getRootFromTip(request);
FileObject a = getFileObject(foList, "a.txt");
@@ -159,7 +155,7 @@ public class HgBrowseCommandTest extends AbstractHgCommandTestBase {
assertNotNull(result);
FileObject root = result.getFile();
List<FileObject> foList = root.getChildren();
Collection<FileObject> foList = root.getChildren();
assertNotNull(foList);
assertFalse(foList.isEmpty());
@@ -181,33 +177,22 @@ public class HgBrowseCommandTest extends AbstractHgCommandTestBase {
*
* @return
*/
private FileObject getFileObject(List<FileObject> foList, String name)
private FileObject getFileObject(Collection<FileObject> foList, String name)
{
FileObject a = null;
for (FileObject f : foList)
{
if (name.equals(f.getName()))
{
a = f;
break;
}
}
assertNotNull(a);
return a;
return foList.stream()
.filter(f -> name.equals(f.getName()))
.findFirst()
.orElseThrow(() -> new AssertionError("file " + name + " not found"));
}
private List<FileObject> getRootFromTip(BrowseCommandRequest request) throws IOException {
private Collection<FileObject> getRootFromTip(BrowseCommandRequest request) throws IOException {
BrowserResult result = new HgBrowseCommand(cmdContext,
repository).getBrowserResult(request);
assertNotNull(result);
FileObject root = result.getFile();
List<FileObject> foList = root.getChildren();
Collection<FileObject> foList = root.getChildren();
assertNotNull(foList);
assertFalse(foList.isEmpty());