Skip to content

Commit

Permalink
Adding unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Oct 30, 2014
1 parent 1722c88 commit 25c12b7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
@@ -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());
}
}
Expand Up @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit 25c12b7

Please sign in to comment.