mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-21 11:31:38 +01:00
more unit tests for ahc
This commit is contained in:
@@ -32,6 +32,8 @@
|
||||
package sonia.scm.net.ahc;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.io.CharStreams;
|
||||
@@ -87,5 +89,42 @@ public class AdvancedHttpResponseTest {
|
||||
byte[] data = ByteStreams.toByteArray(response.contentAsStream());
|
||||
assertEquals("cde456", new String(data, Charsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFirstHeader() throws IOException
|
||||
{
|
||||
Multimap<String,String> mm = LinkedHashMultimap.create();
|
||||
mm.put("Test", "One");
|
||||
mm.put("Test-2", "One");
|
||||
mm.put("Test-2", "Two");
|
||||
when(response.getHeaders()).thenReturn(mm);
|
||||
assertEquals("One", response.getFirstHeader("Test"));
|
||||
assertEquals("One", response.getFirstHeader("Test-2"));
|
||||
assertNull(response.getFirstHeader("Test-3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsSuccessful() throws IOException
|
||||
{
|
||||
// successful
|
||||
when(response.getStatus()).thenReturn(200);
|
||||
assertTrue(response.isSuccessful());
|
||||
when(response.getStatus()).thenReturn(201);
|
||||
assertTrue(response.isSuccessful());
|
||||
when(response.getStatus()).thenReturn(204);
|
||||
assertTrue(response.isSuccessful());
|
||||
when(response.getStatus()).thenReturn(301);
|
||||
assertTrue(response.isSuccessful());
|
||||
|
||||
// not successful
|
||||
when(response.getStatus()).thenReturn(400);
|
||||
assertFalse(response.isSuccessful());
|
||||
when(response.getStatus()).thenReturn(404);
|
||||
assertFalse(response.isSuccessful());
|
||||
when(response.getStatus()).thenReturn(500);
|
||||
assertFalse(response.isSuccessful());
|
||||
when(response.getStatus()).thenReturn(199);
|
||||
assertFalse(response.isSuccessful());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -113,7 +113,7 @@ public class BaseHttpRequestTest {
|
||||
public void testHeaderMultiple(){
|
||||
request.header("a", "b", "c", "d");
|
||||
Collection<String> values = request.getHeaders().get("a");
|
||||
assertThat(values, containsInAnyOrder("b", "c", "d"));
|
||||
assertThat(values, contains("b", "c", "d"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user