Clean up git cat command

This commit is contained in:
René Pfeuffer
2018-08-15 09:24:21 +02:00
parent 3038d6460c
commit 267ef50e51
2 changed files with 80 additions and 171 deletions

View File

@@ -32,19 +32,16 @@
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import sonia.scm.repository.GitConstants;
import sonia.scm.repository.PathNotFoundException;
import sonia.scm.repository.RepositoryException;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import sonia.scm.repository.GitConstants;
import java.io.InputStream;
import static org.junit.Assert.assertEquals;
/**
* Unit tests for {@link GitCatCommand}.
@@ -53,15 +50,8 @@ import sonia.scm.repository.GitConstants;
*
* @author Sebastian Sdorra
*/
public class GitCatCommandTest extends AbstractGitCommandTestBase
{
public class GitCatCommandTest extends AbstractGitCommandTestBase {
/**
* Tests cat command with default branch.
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testDefaultBranch() throws IOException, RepositoryException {
// without default branch, the repository head should be used
@@ -75,16 +65,8 @@ public class GitCatCommandTest extends AbstractGitCommandTestBase
assertEquals("a and b", execute(request));
}
/**
* Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testCat() throws IOException, RepositoryException
{
public void testCat() throws IOException, RepositoryException {
CatCommandRequest request = new CatCommandRequest();
request.setPath("a.txt");
@@ -92,36 +74,37 @@ public class GitCatCommandTest extends AbstractGitCommandTestBase
assertEquals("a and b", execute(request));
}
/**
* Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testSimpleCat() throws IOException, RepositoryException
{
public void testSimpleCat() throws IOException, RepositoryException {
CatCommandRequest request = new CatCommandRequest();
request.setPath("b.txt");
assertEquals("b", execute(request));
}
/**
* Method description
*
*
* @param request
*
* @return
*
* @throws IOException
* @throws RepositoryException
*/
private String execute(CatCommandRequest request)
throws IOException, RepositoryException
{
@Test(expected = PathNotFoundException.class)
public void testUnknownFile() throws IOException, RepositoryException {
CatCommandRequest request = new CatCommandRequest();
request.setPath("unknown");
assertEquals("b", execute(request));
}
@Test
public void testSimpleStream() throws IOException, RepositoryException {
CatCommandRequest request = new CatCommandRequest();
request.setPath("b.txt");
InputStream catResultStream = new GitCatCommand(createContext(), repository).getCatResultStream(request);
assertEquals('b', catResultStream.read());
assertEquals('\n', catResultStream.read());
assertEquals(-1, catResultStream.read());
catResultStream.close();
}
private String execute(CatCommandRequest request) throws IOException, RepositoryException {
String content = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();