Skip to content

Commit

Permalink
robust test coverage (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchen293 authored Nov 30, 2022
1 parent b4bee41 commit 0c7d924
Show file tree
Hide file tree
Showing 45 changed files with 3,538 additions and 879 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
- Removes deprecated class `CreditCard` and its associated classes `PrimaryPaymentMethod`, `SecondaryPaymentMethod`, and `BaseCreditCard`, please use alternative `Billing` class
- Removes all the setters of each object
- Setters are now available via lombok and aren't explicitly in the code anymore
- Change the type `hasMore` in ReferralCustomerCollection from `boolean` to `Boolean`
- Rename some getters
- Changes the type `hasMore` in ReferralCustomerCollection from `boolean` to `Boolean`
- Renames some getters
- Pickup class: `getPickoutRates()` -> `getPickupRates()`
- PaymentMethod class: `getPrimaryPaymentMethodObject()` -> `getPrimaryPaymentMethod()`
- PaymentMethod class: `getSecondaryPaymentMethodObject()` -> `getSecondaryPaymentMethod()`
- Removes the `refresh()` function in all classes, please use `retrieve()` function instead
- Removes invalid functions that allow users to make an API request without providing required parameters

## v5.10.0 (2022-09-21)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![CI](https://github.com/EasyPost/easypost-java/workflows/CI/badge.svg)](https://github.com/EasyPost/easypost-java/actions?query=workflow%3ACI)
[![Maven Central](https://img.shields.io/maven-central/v/com.easypost/easypost-api-client?label=Maven%20Central)](https://search.maven.org/artifact/com.easypost/easypost-api-client)
[![Coverage Status](https://coveralls.io/repos/github/EasyPost/easypost-java/badge.svg?branch=master)](https://coveralls.io/github/EasyPost/easypost-java?branch=master)

EasyPost, the simple shipping solution. You can sign up for an account at <https://easypost.com>.

Expand Down
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
</scm>

<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>4.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down Expand Up @@ -121,6 +127,12 @@
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<configuration>
<excludes>
<!-- Exclude all the getters in model for code coverage -->
<exclude>**/model/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class InvalidParameterError extends EasyPostException{
* @param message the exception message
*/
public InvalidParameterError(final String message) {
super(message);
this(message, null);
}

/**
Expand Down
39 changes: 3 additions & 36 deletions src/main/java/com/easypost/http/EasyPostResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,13 @@

package com.easypost.http;

import lombok.Getter;

@Getter
public class EasyPostResponse {
private int responseCode;
private String responseBody;

/**
* Get HTTP response body.
*
* @return HTTP response body
*/
public String getResponseBody() {
return responseBody;
}

/**
* Set HTTP response body.
*
* @param responseBody HTTP response body
*/
public void setResponseBody(final String responseBody) {
this.responseBody = responseBody;
}

/**
* Get HTTP response code.
*
* @return HTTP response code
*/
public int getResponseCode() {
return responseCode;
}

/**
* Set HTTP response code.
*
* @param responseCode HTTP response code
*/
public void setResponseCode(final int responseCode) {
this.responseCode = responseCode;
}

/**
* Constructor.
*
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/easypost/http/Requestor.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import lombok.Generated;

import javax.net.ssl.HttpsURLConnection;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -81,10 +83,6 @@ static Map<String, String> generateHeaders(String apiKey) throws MissingParamete
convertSpaceToHyphen(System.getProperty("os.arch")),
convertSpaceToHyphen(System.getProperties().getProperty("java.vm.name"))));

if (apiKey == null || apiKey.isEmpty()) {
throw new MissingParameterError(Constants.INVALID_API_KEY_TYPE);
}

headers.put("Authorization", String.format("Bearer %s", apiKey));

return headers;
Expand Down Expand Up @@ -566,6 +564,7 @@ protected static void handleAPIError(String rBody, final int rCode) throws EasyP
}
}

@Generated // Exclude from the jacoco test coverage
private static EasyPostResponse makeAppEngineRequest(final RequestMethod method, String url, final String query,
final JsonObject body, final EasyPostClient client)
throws EasyPostException {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/easypost/model/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.List;
import java.util.Map;

import com.easypost.exception.EasyPostException;
import com.easypost.utils.Utilities;

import lombok.Getter;

@Getter
Expand All @@ -20,4 +23,38 @@ public final class Order extends EasyPostResource {
private Map<String, Object> options;
private List<ShipmentMessage> messages;
private List<CarrierAccount> carrierAccounts;

/**
* Get the lowest rate for this Order.
*
* @return Lowest Rate object
* @throws EasyPostException when the request fails.
*/
public Rate lowestRate() throws EasyPostException {
return this.lowestRate(null, null);
}

/**
* Get the lowest rate for this Order.
*
* @param carriers The carriers to use in the filter.
* @param services The services to use in the filter.
* @return Lowest Rate object
* @throws EasyPostException when the request fails.
*/
public Rate lowestRate(final List<String> carriers, final List<String> services)
throws EasyPostException {
return Utilities.getLowestObjectRate(this.getRates(), carriers, services);
}

/**
* Get the lowest rate for this order.
*
* @param carriers The carriers to use in the query.
* @return Rate object
* @throws EasyPostException when the request fails.
*/
public Rate lowestRate(final List<String> carriers) throws EasyPostException {
return this.lowestRate(carriers, null);
}
}
45 changes: 45 additions & 0 deletions src/main/java/com/easypost/model/Pickup.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.easypost.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.easypost.exception.EasyPostException;
import com.easypost.utils.Utilities;

import lombok.Getter;

@Getter
Expand All @@ -17,4 +22,44 @@ public final class Pickup extends EasyPostResource {
private Address address;
private List<CarrierAccount> carrierAccounts;
private List<PickupRate> pickupRates;

/**
* Get the lowest rate for this Pickup.
*
* @return lowest PickupRate object
* @throws EasyPostException when the request fails.
*/
public PickupRate lowestRate() throws EasyPostException {
return this.lowestRate(null, null);
}

/**
* Get the lowest rate for this Pickup.
*
* @param carriers The carriers to use in the filter.
* @param services The services to use in the filter.
* @return lowest PickupRate object
* @throws EasyPostException when the request fails.
*/
public PickupRate lowestRate(final List<String> carriers, final List<String> services)
throws EasyPostException {
List<Rate> rates = new ArrayList<Rate>();

for (PickupRate rate : this.getPickupRates()) {
rates.add((Rate) rate);
}

return (PickupRate) Utilities.getLowestObjectRate(rates, carriers, services);
}

/**
* Get the lowest rate for this pickup.
*
* @param carriers The carriers to use in the query.
* @return PickupRate object
* @throws EasyPostException when the request fails.
*/
public PickupRate lowestRate(final List<String> carriers) throws EasyPostException {
return this.lowestRate(carriers, null);
}
}
36 changes: 0 additions & 36 deletions src/main/java/com/easypost/service/BatchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,42 +87,6 @@ public Batch createAndBuy(final Map<String, Object> params) throws EasyPostExcep
client);
}

/**
* Refresh this Batch object.
*
* @param id The ID of batch.
* @return Batch object.
* @throws EasyPostException when the request fails.
*/
public Batch refresh(String id) throws EasyPostException {
return this.refresh(id, null);
}

/**
* Refresh this Batch object.
*
* @param id The ID of batch.
* @param params Map of parameters.
* @return Batch object.
* @throws EasyPostException when the request fails.
*/
public Batch refresh(final String id, final Map<String, Object> params) throws EasyPostException {
String url = String.format("%s", Utilities.instanceURL(Batch.class, id));

return Requestor.request(RequestMethod.GET, url, params, Batch.class, client);
}

/**
* Label this Batch object.
*
* @param id The ID of batch.
* @return Batch object.
* @throws EasyPostException when the request fails.
*/
public Batch label(String id) throws EasyPostException {
return this.label(id, null);
}

/**
* Label this Batch object.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/easypost/service/EasyPostClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public EasyPostClient(String apiKey, String apiBase) throws MissingParameterErro
* @throws MissingParameterError
*/
public EasyPostClient(String apiKey, int connectTimeoutMilliseconds) throws MissingParameterError {
this(apiKey, connectTimeoutMilliseconds, Constant.DEFAULT_READ_TIMEOUT_MILLISECONDS, Constant.API_BASE);
this(apiKey, connectTimeoutMilliseconds, Constant.API_BASE);
}

/**
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/com/easypost/service/InsuranceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,4 @@ public InsuranceCollection all(final Map<String, Object> params)
return Requestor.request(RequestMethod.GET, Utilities.classURL(Insurance.class),
params, InsuranceCollection.class, client);
}

/**
* Refresh this Insurance.
*
* @param id The ID of insurance.
* @return Insurance object
* @throws EasyPostException when the request fails.
*/
public Insurance refresh(final String id) throws EasyPostException {
return this.refresh(id, null);
}

/**
* Refresh this Insurance.
*
* @param params Map of parameters.
* @param id The ID of insurance.
* @return Insurance object
* @throws EasyPostException when the request fails.
*/
public Insurance refresh(final String id, final Map<String, Object> params) throws EasyPostException {
return Requestor.request(RequestMethod.GET,
String.format("%s", Utilities.instanceURL(Insurance.class, id)), params, Insurance.class,
client);
}
}
Loading

0 comments on commit 0c7d924

Please sign in to comment.