Skip to content

Commit

Permalink
update javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed Sep 25, 2020
1 parent bdb9cd3 commit 8315cd4
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
6 changes: 3 additions & 3 deletions unirest-mocks/src/main/java/kong/unirest/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ public interface Assert {
* Assert that any request to this method/path contained this header
* @param key the expected header key
* @param value the expected header value
* @throws UnirestAssertion
* @throws UnirestAssertion when header does not exist
*/
void assertHeader(String key, String value);

/**
* assert that this instance of method/path was invoked x times
* @param i the number of times invoked.
* @throws UnirestAssertion
* @throws UnirestAssertion when the invocation count is not x
*/
void assertInvokedTimes(int i);

/**
* verify that all Expectations were fulfilled at least once.
* @throws UnirestAssertion
* @throws UnirestAssertion when all expectations have not been fulfilled
*/
void verifyAll();
}
3 changes: 3 additions & 0 deletions unirest-mocks/src/main/java/kong/unirest/Expectation.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,21 @@ public interface Expectation {

/**
* expect a string response
* @param body the expected response body
* @return The ExpectedResponse
*/
ExpectedResponse thenReturn(String body);

/**
* expect a json response
* @param jsonObject the expected response body
* @return The ExpectedResponse
*/
ExpectedResponse thenReturn(JSONElement jsonObject);

/**
* expect a json response as defined by a pojo
* @param pojo the expected response body
* @return The ExpectedResponse
*/
ExpectedResponse thenReturn(Object pojo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

package kong.unirest;

/**
* Thrown to indicate that an assertion has failed.
*/
public class UnirestAssertion extends AssertionError {
public UnirestAssertion(String base, Object... args){
super(String.format(base, args));
Expand Down
25 changes: 25 additions & 0 deletions unirest-mocks/src/test/java/kong/tests/AsyncTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
/**
* The MIT License
*
* Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package kong.tests;

import kong.unirest.HttpMethod;
Expand Down
12 changes: 11 additions & 1 deletion unirest/src/main/java/kong/unirest/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public Builder backingCache(Cache cache) {
/**
* Provide a custom key generator.
* The default key is a hash of the request, the request execution type and the response type.
* @param keyGenerator
* @param keyGenerator a custom cache key generator
* @return this builder
*/
public Builder withKeyGen(KeyGenerator keyGenerator) {
Expand All @@ -126,8 +126,18 @@ public Builder withKeyGen(KeyGenerator keyGenerator) {
}
}

/**
* A functional interface to generate a cache key
*/
@FunctionalInterface
interface KeyGenerator {
/**
* A function to generate a cache key
* @param request the current http request
* @param isAsync indicates if this request is being executed async
* @param responseType the response type (String, JsonNode, etc)
* @return a key which can be used as a hash for the cache
*/
Key apply(HttpRequest request, Boolean isAsync, Class<?> responseType);
}

Expand Down
2 changes: 1 addition & 1 deletion unirest/src/main/java/kong/unirest/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ public Config addShutdownHook(boolean value) {
* for example. Setting a default path of 'http://somwhere'
* and then calling Unirest with Unirest.get('/place')
* will result in a path of 'https://somwehre/place'
* @param value
* @param value the base URL to use
* @return this config object
*/
public Config defaultBaseUrl(String value) {
Expand Down

0 comments on commit 8315cd4

Please sign in to comment.