Skip to content
Permalink
Browse files

Adding unit test

  • Loading branch information...
ajs6f committed Oct 30, 2014
1 parent 1722c88 commit 25c12b756391131b8d10895f36791b295debba68
@@ -0,0 +1,30 @@
package org.fcrepo.http.commons.domain;

import static com.google.common.collect.Sets.newHashSet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.text.ParseException;

import org.junit.Test;


public class MultiPreferTest extends SinglePreferTest {

@Override
protected SinglePrefer createTestPreferTypeFromHeader(String header) throws ParseException {
return new MultiPrefer(header);
}

@Test
public void testMultiConstructor() throws ParseException {
SinglePrefer first = new SinglePrefer();
SinglePrefer second = new SinglePrefer("return=representation");
SinglePrefer third = new SinglePrefer("handling=strict");
MultiPrefer testPrefer = new MultiPrefer(newHashSet(first, second, third));
// check to see that both headers were parsed
assertTrue(testPrefer.hasReturn());
assertEquals("representation", testPrefer.getReturn().getValue());
assertTrue(testPrefer.hasHandling());
}
}
@@ -24,27 +24,32 @@

/**
* @author cabeer
* @author ajs6f
*/
public class SinglePreferTest {

protected SinglePrefer createTestPreferTypeFromHeader(String header) throws ParseException {
return new SinglePrefer(header);
}

@Test
public void testHasReturn() throws ParseException {
final SinglePrefer prefer = new SinglePrefer("return=representation");
final SinglePrefer prefer = createTestPreferTypeFromHeader("return=representation");

assertTrue(prefer.hasReturn());
}

@Test
public void testGetReturn() throws ParseException {
final SinglePrefer prefer = new SinglePrefer("return=representation");
final SinglePrefer prefer = createTestPreferTypeFromHeader("return=representation");

assertEquals("representation", prefer.getReturn().getValue());
}

@Test
public void testGetReturnParameters() throws ParseException {
final SinglePrefer prefer =
new SinglePrefer("return=representation; include=\"http://www.w3.org/ns/ldp#PreferMinimalContainer\"");
createTestPreferTypeFromHeader("return=representation; include=\"http://www.w3.org/ns/ldp#PreferMinimalContainer\"");

assertTrue(prefer.hasReturn());
assertEquals("representation", prefer.getReturn().getValue());
@@ -55,22 +60,22 @@ public void testGetReturnParameters() throws ParseException {

@Test
public void testHasHandling() throws ParseException {
final SinglePrefer prefer = new SinglePrefer("handling=strict");
final SinglePrefer prefer = createTestPreferTypeFromHeader("handling=strict");

assertTrue(prefer.hasHandling());
}

@Test
public void testGetHandling() throws ParseException {
final SinglePrefer prefer = new SinglePrefer("handling=lenient");
final SinglePrefer prefer = createTestPreferTypeFromHeader("handling=lenient");

assertEquals("lenient", prefer.getHandling().getValue());
}

@Test
public void testGetHandlingParameters() throws ParseException {
final SinglePrefer prefer =
new SinglePrefer("handling=lenient; some=\"parameter\"");
createTestPreferTypeFromHeader("handling=lenient; some=\"parameter\"");

assertTrue(prefer.hasHandling());
assertEquals("lenient", prefer.getHandling().getValue());

0 comments on commit 25c12b7

Please sign in to comment.
You can’t perform that action at this time.