Skip to content

Commit

Permalink
update javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed Dec 4, 2023
1 parent dea0f93 commit 29aca9d
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 4.2.1
* #503 Remove old retry setting that no longer works with the Java client
* #504 allow asserting just one expectation verification on mock asserts

## 4.1.1
* issue #493: Copy status text from MockResponse
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ You can use a maven bom to manage the modules:
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java-bom</artifactId>
<version>4.1.1</version>
<version>4.1.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
2 changes: 0 additions & 2 deletions unirest-mocks/src/main/java/kong/unirest/core/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,4 @@ public interface Assert {
* @throws UnirestAssertion when all expectations have not been fulfilled
*/
Assert verifyAll();


}
29 changes: 0 additions & 29 deletions unirest-mocks/src/main/java/kong/unirest/core/BodySummary.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@

import java.util.function.Supplier;

/**
* The expected response of a assertion.
* Contains things like response status, body and headers.
*/
public interface ExpectedResponse {
/**
* Create a independent expected response. useful for
* systems creating test-doubles rather than strict mocking
* @param status the response status.
* @return a new expected response with this status.
*/
static ExpectedResponse of(int status) {
return new ExpectedResponseRecord(null).withStatus(status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.util.function.BiConsumer;

/**
* A Mock of a websocket that sends messages directly to a single listener on the other side/
* A Mock of a websocket that sends messages directly to a single listener on the other side
*/
public class MockWebSocket implements WebSocket {
private SocketSet remoteSocketSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

/**
* A socket set represents a websocket and the listener for a target.
* Each side of a websocket communcation would be represented by a set
* Each side of a websocket communication would be represented by a set
*/
public class SocketSet<S extends WebSocket, L extends WebSocket.Listener> {

Expand Down
29 changes: 29 additions & 0 deletions unirest/src/main/java/kong/unirest/core/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,39 @@

package kong.unirest.core;

/**
* Interface for object mappers that can transform response bodies to other structures.
*/
public interface ObjectMapper {

/**
* reads the content from the request as a string and transforms to a type passed by the
* asObject method on the Unirest builder.
* @param value the content as a string.
* @param valueType the type to map to
* @return the object mapped into the class type
* @param <T> the type
*/
<T> T readValue(String value, Class<T> valueType);

/**
* reads the content from the request as a string and transforms to a type passed by the
* asObject method on the Unirest builder.
* This method takes a GenericType which retains Generics information for types lke List&lt;Foo&gt;
* @param value the content as a string.
* @param genericType the generic type
* @return the object mapped into the class type
* @param <T> the type
*/
default <T> T readValue(String value, GenericType<T> genericType){
throw new UnirestException("Please implement me");
}

/**
* Takes a object and serialize it as a string.
* This is used to map objects to bodies to pass to requests
* @param value the object to serialize to a string
* @return the serialized string of the object
*/
String writeValue(Object value);
}
104 changes: 103 additions & 1 deletion unirest/src/main/java/kong/unirest/core/RawResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,121 @@
import java.io.InputStream;
import java.io.InputStreamReader;

/**
* The Raw Response represents the response before any mapping or consumption of the content.
*/
public interface RawResponse {
/**
* Returns the status code for this response.
*
* @return the response code
*/
int getStatus();

/**
* Returns the status text for this response.
*
* @return the response text
*/
String getStatusText();

/**
* Returns the received response headers.
*
* @return the response headers
*/
Headers getHeaders();

/**
* Returns the body content of the response as a InputStream.
* Like most InputStreams it can only be read once. If you read
* the response though some other method like getContentAsBytes()
* or getBodyAsString() it will read this method and consume the InputStream
*
* @return the content
*/
InputStream getContent();

/**
* Returns the body as bytes. This consumes the entire InputStream.
* Warning: Calling this on very large responses will place all data in
* memory and could create OutOfMemory errors
*
* @return the content as bytes
*/
byte[] getContentAsBytes();

/**
* Returns the body as UTF-8 String. This consumes the entire InputStream.
* Warning: Calling this on very large responses will place all data in
* memory and could create OutOfMemory errors
*
* Using this method with a binary response will make you sad
*
* @return the content as a UTF-8 String
*/
String getContentAsString();

/**
* Returns the body as UTF-8 String. This consumes the entire InputStream.
* Warning: Calling this on very large responses will place all data in
* memory and could create OutOfMemory errors
*
* Using this method with a binary response will make you sad
*
* @param charset the charset for the String
* @return the content as a string in the provided charset.
*/
String getContentAsString(String charset);

/**
* Returns the body content of the response as a InputStreamReader.
* Like most InputStreams it can only be read once. If you read
* the response though some other method like getContentAsBytes()
* or getBodyAsString() it will read this method and consume the InputStream
*
* @return the content
*/
InputStreamReader getContentReader();

/**
* Indicates that the response has content
* @return boolean indicating that the response has content.
*/
boolean hasContent();

/**
* Returns the mime type of the response content as indicated by
* the Content-Type header or a empty string if none is supplied
* (e.g. application/json)
* @return the Content-Type
*/
String getContentType();

/**
* Returns the encoding of the response as indicated by the Content-Encoding header
* or returns a empty string if none provided.
*
* @return the encoding
*/
String getEncoding();

/**
* Returns the current config for this request/response
* @return the config
*/
Config getConfig();
HttpResponseSummary toSummary();

/**
* returns a lightweight read only summary of the request.
*
* @return the request summary
*/
HttpRequestSummary getRequestSummary();

/**
* returns a lightweight read only summary of the response.
* @return the response summary
*/
HttpResponseSummary toSummary();
}

0 comments on commit 29aca9d

Please sign in to comment.