package pl.itcrowd.youtrack.api.rest; import org.junit.Test; import pl.itcrowd.youtrack.api.YoutrackUnmarshaller; import pl.itcrowd.youtrack.api.exceptions.YoutrackAPIException; import javax.xml.bind.JAXBException; import java.io.IOException; import static junit.framework.Assert.assertEquals; public class YoutrackUnmarshallerTest { @Test public void unmarshalEmptyError() throws JAXBException, IOException { // Given final String extendedErrorResponse = ""; // When final String errorText = YoutrackUnmarshaller.unmarshalError(extendedErrorResponse); // THen assertEquals("", errorText); } @Test public void unmarshalError() throws JAXBException, IOException { // Given final String extendedErrorResponse = "Estimated completion time"; // When final String errorText = YoutrackUnmarshaller.unmarshalError(extendedErrorResponse); // THen assertEquals("Estimated completion time", errorText); } @Test public void unmarshalExtendedError() throws JAXBException, IOException { // Given final String extendedErrorResponse = "Estimate task before starting work on itEstimated completion time"; // When final String errorText = YoutrackUnmarshaller.unmarshalError(extendedErrorResponse); // Then assertEquals("Estimate task before starting work on it", errorText); } @Test public void unmarshalExtendedErrorWithMessageOnly() throws JAXBException, IOException { // Given final String extendedErrorResponse = "Estimate task before starting work on it"; // When final String errorText = YoutrackUnmarshaller.unmarshalError(extendedErrorResponse); // Then assertEquals("Estimate task before starting work on it", errorText); } @Test public void unmarshalExtendedErrorWithEmptyMessage() throws JAXBException, IOException { // Given final String extendedErrorResponse = "Estimated completion time"; // When final String errorText = YoutrackUnmarshaller.unmarshalError(extendedErrorResponse); // Then assertEquals("", errorText); } @Test(expected = YoutrackAPIException.class) public void unmarshalExtendedErrorWithoutMessage() throws JAXBException, IOException { // Given final String extendedErrorResponse = "Estimated completion time"; // When YoutrackUnmarshaller.unmarshalError(extendedErrorResponse); } }