Skip to content

Commit

Permalink
(#171) Add @since on inner class & fix indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Jun 25, 2020
1 parent 6197ea7 commit 25ecdaa
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/main/java/com/jcabi/http/mock/MkAnswer.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,42 @@ public interface MkAnswer {

/**
* Simple implementation.
*
* @since 1.0
*/
@Immutable
@EqualsAndHashCode(of = { "code", "hdrs", "content" })
@EqualsAndHashCode(of = {"code", "hdrs", "content"})
@Loggable(Loggable.DEBUG)
final class Simple implements MkAnswer {
/**
* The Charset to use.
*/
private static final Charset CHARSET = Charset.forName("UTF-8");

/**
* Encapsulated response.
*/
private final transient int code;

/**
* Headers.
*/
private final transient Array<Map.Entry<String, String>> hdrs;

/**
* Content received.
*/
@Immutable.Array
private final transient byte[] content;

/**
* Public ctor.
* @param body Body of HTTP response
*/
public Simple(final String body) {
this(HttpURLConnection.HTTP_OK, body);
}

/**
* Public ctor (with empty HTTP body).
* @param status HTTP status
Expand All @@ -116,6 +123,7 @@ public Simple(final String body) {
public Simple(final int status) {
this(status, "");
}

/**
* Public ctor.
* @param status HTTP status
Expand All @@ -127,6 +135,7 @@ public Simple(final int status, final String body) {
body.getBytes(MkAnswer.Simple.CHARSET)
);
}

/**
* Public ctor.
* @param status HTTP status
Expand All @@ -137,13 +146,15 @@ public Simple(final int status,
final Iterable<Map.Entry<String, String>> headers,
final byte[] body) {
this.code = status;
this.hdrs = new Array<Map.Entry<String, String>>(headers);
this.hdrs = new Array<>(headers);
this.content = body.clone();
}

@Override
public int status() {
return this.code;
}

@Override
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public Map<String, List<String>> headers() {
Expand All @@ -155,14 +166,17 @@ public Map<String, List<String>> headers() {
}
return map;
}

@Override
public String body() {
return new String(this.content, MkAnswer.Simple.CHARSET);
}

@Override
public byte[] bodyBytes() {
return this.content.clone();
}

@Override
public String toString() {
final StringBuilder text = new StringBuilder(0)
Expand All @@ -180,6 +194,7 @@ public String toString() {
.append(new RequestBody.Printable(this.content))
.toString();
}

/**
* Make a copy of this answer, with an extra header.
* @param name Name of the header
Expand All @@ -194,6 +209,7 @@ public MkAnswer.Simple withHeader(final String name,
this.content
);
}

/**
* Make a copy of this answer, with another status code.
* @param status Status code
Expand All @@ -206,6 +222,7 @@ public MkAnswer.Simple withStatus(final int status) {
this.content
);
}

/**
* Make a copy of this answer, with another body.
* @param body Body
Expand All @@ -218,6 +235,7 @@ public MkAnswer.Simple withBody(final String body) {
body.getBytes(MkAnswer.Simple.CHARSET)
);
}

/**
* Make a copy of this answer, with another body.
* @param body Body
Expand Down

0 comments on commit 25ecdaa

Please sign in to comment.