001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006
007package org.fcrepo.http.commons.exceptionhandlers;
008
009import static javax.ws.rs.core.Response.Status.PRECONDITION_FAILED;
010import static org.junit.Assert.assertEquals;
011
012import javax.ws.rs.core.Response;
013
014import org.fcrepo.kernel.api.exception.PreconditionException;
015
016import org.junit.Before;
017import org.junit.Test;
018
019/**
020 * PreconditionExceptionTest class.
021 *
022 * @author dbernstein
023 * @since Jun 22, 2017
024 */
025public class PreconditionExceptionMapperTest {
026
027    private PreconditionExceptionMapper testObj;
028
029    @Before
030    public void setUp() {
031        testObj = new PreconditionExceptionMapper();
032    }
033
034    @Test
035    public void testToResponse() {
036        final String message = "error message";
037        final PreconditionException input = new PreconditionException(message, PRECONDITION_FAILED.getStatusCode());
038        final Response actual = testObj.toResponse(input);
039        assertEquals(PRECONDITION_FAILED.getStatusCode(), actual.getStatus());
040        assertEquals(message, actual.getEntity().toString());
041
042    }
043}