All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.kristofa.test.http.HttpResponseImpl Maven / Gradle / Ivy

Go to download

Mock and Proxy HTTP Server for testing purposes. Forked from https://github.com/jharlap/mock-http-server

There is a newer version: 4.1
Show newest version
package com.github.kristofa.test.http;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
 * HttpResponse implementation.
 * 
 * @author kristof
 */
public class HttpResponseImpl implements HttpResponse {

    private final int httpCode;
    private final String contentType;
    private final byte[] content;

    /**
     * Creates a new instance.
     * 
     * @param httpCode http response code.
     * @param contentType Content type, can be null.
     * @param content Content, can be null.
     */
    public HttpResponseImpl(final int httpCode, final String contentType, final byte[] content) {
        this.httpCode = httpCode;
        this.contentType = contentType;
        this.content = content;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getHttpCode() {
        return httpCode;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getContentType() {
        return contentType;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public byte[] getContent() {
        return content;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "Http code: " + getHttpCode() + ", Content Type: " + (getContentType() == null ? "null" : getContentType())
            + ", Content: " + (getContent() == null ? "null" : new String(getContent()));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this, false);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(final Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj, false);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy