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,15 +33,13 @@
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import sonia.scm.repository.BrowserResult;
import sonia.scm.repository.FileObject;
import sonia.scm.repository.RevisionNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -49,8 +47,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra
@@ -70,7 +66,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
@Test
public void testBrowse() throws RevisionNotFoundException {
List<FileObject> foList = getRootFromTip(new BrowseCommandRequest());
Collection<FileObject> foList = getRootFromTip(new BrowseCommandRequest());
FileObject a = getFileObject(foList, "a.txt");
FileObject c = getFileObject(foList, "c");
@@ -102,7 +98,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
assertNotNull(result);
List<FileObject> foList = result.getFile().getChildren();
Collection<FileObject> foList = result.getFile().getChildren();
assertNotNull(foList);
assertFalse(foList.isEmpty());
@@ -145,7 +141,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
request.setDisableLastCommit(true);
List<FileObject> foList = getRootFromTip(request);
Collection<FileObject> foList = getRootFromTip(request);
FileObject a = getFileObject(foList, "a.txt");
@@ -161,7 +157,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
assertNotNull(result);
List<FileObject> foList = result.getFile().getChildren();
Collection<FileObject> foList = result.getFile().getChildren();
assertNotNull(foList);
assertFalse(foList.isEmpty());
@@ -195,31 +191,20 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
*
* @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 RevisionNotFoundException {
private Collection<FileObject> getRootFromTip(BrowseCommandRequest request) throws RevisionNotFoundException {
BrowserResult result = createCommand().getBrowserResult(request);
assertNotNull(result);
List<FileObject> foList = result.getFile().getChildren();
Collection<FileObject> foList = result.getFile().getChildren();
assertNotNull(foList);
assertFalse(foList.isEmpty());