8000 Get rid of all deprecated and unused warnings (#30) · Labs64/NetLicensingClient-java@7cf2838 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cf2838

Browse files
authored
Get rid of all deprecated and unused warnings (#30)
1 parent a2d63bd commit 7cf2838

File tree

18 files changed

+179
-178
lines changed

18 files changed

+179
-178
lines changed

NetLicensingClient-demo/src/main/java/com/labs64/netlicensing/demo/NetLicensingClientDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static void main(final String[] args) {
5353
if (AllExamples.list.containsKey(exampleToRun)) {
5454
NetLicensingExample ex;
5555
try {
56-
ex = AllExamples.list.get(exampleToRun).newInstance();
56+
ex = AllExamples.list.get(exampleToRun).getConstructor().newInstance();
5757
ex.execute();
5858
return;
5959
} catch (final Exception e) {

NetLicensingClient-demo/src/main/java/com/labs64/netlicensing/examples/CallEveryAPIMethod.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import com.labs64.netlicensing.domain.vo.Context;
3939
import com.labs64.netlicensing.domain.vo.Currency;
4040
import com.labs64.netlicensing.domain.vo.LicenseType;
41-
import com.labs64.netlicensing.domain.vo.LicenseeSecretMode;
4241
import com.labs64.netlicensing.domain.vo.Page;
4342
import com.labs64.netlicensing.domain.vo.SecurityMode;
4443
import com.labs64.netlicensing.domain.vo.TokenType;
@@ -121,8 +120,6 @@ public void execute() {
121120

122121
final Product updateProduct = new ProductImpl();
123122
updateProduct.addProperty("Updated property name", "Updated value");
124-
updateProduct.addProperty(Constants.Product.PROP_LICENSEE_SECRET_MODE,
125-
LicenseeSecretMode.PREDEFINED.toString());
126123
product = ProductService.update(context, productNumber, updateProduct);
127124
out.writeObject("Updated product:", product);
128125

@@ -239,7 +236,6 @@ public void execute() {
239236

240237
final Licensee updateLicensee = new LicenseeImpl();
241238
updateLicensee.addProperty("Updated property name", "Updated value");
242-
updateLicensee.addProperty(Constants.Licensee.PROP_LICENSEE_SECRET, randomLicenseeSecret);
243239

244240
licensee = LicenseeService.update(context, licenseeNumber, updateLicensee);
245241
out.writeObject("Updated licensee:", licensee);

NetLicensingClient/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
<groupId>org.apache.commons</groupId>
3535
<artifactId>commons-collections4</artifactId>
3636
</dependency>
37+
<dependency>
38+
<groupId>org.apache.commons</groupId>
39+
<artifactId>commons-text</artifactId>
40+
<scope>test</scope>
41+
</dependency>
3742
<dependency>
3843
<groupId>commons-io</groupId>
3944
<artifactId>commons-io</artifactId>
@@ -51,6 +56,7 @@
5156
<dependency>
5257
<groupId>junit</groupId>
5358
<artifactId>junit</artifactId>
59+
<scope>test</scope>
5460
</dependency>
5561
<dependency>
5662
<groupId>com.helger</groupId>
@@ -61,10 +67,12 @@
6167
<dependency>
6268
<groupId>org.glassfish.jersey.test-framework</groupId>
6369
<artifactId>jersey-test-framework-core</artifactId>
70+
<scope>test</scope>
6471
</dependency>
6572
<dependency>
6673
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
6774
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
75+
<scope>test</scope>
6876
</dependency>
6977
</dependencies>
7078

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/EntityFactory.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,9 @@ private <T> Converter<Item, T> converterFor(final Class<T> entityClass) {
243243
+ entityClass.getCanonicalName() + ".");
244244
}
245245
try {
246-
converter = (Converter<Item, T>) converterClass.newInstance();
246+
converter = (Converter<Item, T>) converterClass.getConstructor().newInstance();
247247
getConvertersCache().put(entityClass, converter);
248-
} catch (final InstantiationException e) {
249-
throw new RuntimeException(
250-
"Can not instantiate converter of class " + converterClass.getCanonicalName() + ".");
251-
} catch (final IllegalAccessException e) {
248+
} catch (final Throwable e) {
252249
throw new RuntimeException(
253250
"Can not instantiate converter of class " + converterClass.getCanonicalName() + ".");
254251
}

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/impl/LicenseTransactionJoinImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
public class LicenseTransactionJoinImpl implements LicenseTransactionJoin {
2020

21+
private static final long serialVersionUID = -4119701993632165536L;
22+
2123
private Transaction transaction;
2224
private License license;
2325

NetLicensingClient/src/main/java/com/labs64/netlicensing/service/NetLicensingService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.labs64.netlicensing.domain.vo.Context;
2727
import com.labs64.netlicensing.domain.vo.MetaInfo;
2828
import com.labs64.netlicensing.domain.vo.Page;
29-
import com.labs64.netlicensing.exception.BadSignatureException;
3029
import com.labs64.netlicensing.exception.NetLicensingException;
3130
import com.labs64.netlicensing.exception.RestException;
3231
import com.labs64.netlicensing.exception.ServiceException;
@@ -35,8 +34,8 @@
3534
import com.labs64.netlicensing.provider.RestResponse;
3635
import com.labs64.netlicensing.schema.SchemaFunction;
3736
import com.labs64.netlicensing.schema.context.Netlicensing;
38-
import com.labs64.netlicensing.util.SignatureUtils;
3937
import com.labs64.netlicensing.util.CheckUtils;
38+
import com.labs64.netlicensing.util.SignatureUtils;
4039

4140
/**
4241
* Provides generic requests to NetLicensing services. This class is supposed to be used by other **Service classes.

NetLicensingClient/src/main/java/com/labs64/netlicensing/service/ValidationService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public static ValidationResult validateOffline(final Context context, final Netl
101101
return convertValidationResult(validationFile, meta);
102102
}
103103

104+
@SuppressWarnings("deprecation")
104105
private static Form convertValidationParameters(final ValidationParameters validationParameters) {
105106
final Form form = new Form();
106107
if (validationParameters != null) {

NetLicensingClient/src/test/java/com/labs64/netlicensing/service/BaseServiceTest.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package com.labs64.netlicensing.service;
1414

1515
import java.math.BigDecimal;
16+
import java.math.RoundingMode;
1617
import java.util.HashMap;
1718
import java.util.List;
1819
import java.util.Map;
@@ -31,7 +32,7 @@
3132
import javax.ws.rs.core.UriInfo;
3233

3334
import org.apache.commons.lang3.StringUtils;
34-
import org.apache.commons.lang3.text.WordUtils;
35+
import org.apache.commons.text.WordUtils;
3536
import org.glassfish.jersey.server.ResourceConfig;
3637
import org.glassfish.jersey.test.JerseyTest;
3738
import org.glassfish.jersey.test.TestProperties;
@@ -100,7 +101,7 @@ public AbstractNLICServiceResource(final String serviceId) {
100101

101102
/**
102103
* Mock for "create entity" service.
103-
*
104+
*
104105
* @param formParams
105106
* POST request body parameters
106107
* @return response with XML representation of the created entity
@@ -113,7 +114,7 @@ public Response create(final MultivaluedMap<String, String> formParams) {
113114

114115
/**
115116
* Mock for "get entity" service.
116-
*
117+
*
117118
* @return response with XML representation of the entity
118119
*/
119120
@GET
@@ -127,7 +128,7 @@ public Response get(@PathParam("number") final String number) {
127128

128129
/**
129130
* Mock for "list entities" service.
130-
*
131+
*
131132
* @return response with XML representation of the entities page
132133
*/
133134
@GET
@@ -140,7 +141,7 @@ public Response list() {
140141

141142
/**
142143
* Mock for "update entity" service.
143-
*
144+
*
144145
* @param formParams
145146
* POST request body parameters
146147
* @return response with XML representation of the updated entity
@@ -157,7 +158,7 @@ public Response update(@PathParam("number") final String number, final Multivalu
157158
for (final String paramKey : formParams.keySet()) {
158159
final Property property = SchemaFunction.propertyByName(properties, paramKey);
159160
final String paramValue = formParams.getFirst(paramKey);
160-
if (paramValue != null && paramValue.trim().equals("")) {
161+
if ((paramValue != null) && paramValue.trim().equals("")) {
161162
properties.remove(property);
162163
} else {
163164
if (!properties.contains(property)) {
@@ -172,7 +173,7 @@ public Response update(@PathParam("number") final String number, final Multivalu
172173

173174
/**
174175
* Mock for "delete entity" service.
175-
*
176+
*
176177
* @param number
177178
* entity number
178179
* @param uriInfo
@@ -187,7 +188,7 @@ public Response delete(@PathParam("number") final String number, @Context final
187188

188189
/**
189190
* Defines common functionality for a "create entity" service.
190-
*
191+
*
191192
* @param formParams
192193
* POST request body parameters
193194
* @param defaultPropertyValues
@@ -203,7 +204,7 @@ protected Response create(final MultivaluedMap<String, String> formParams,
203204
item.setType(WordUtils.capitalize(serviceId));
204205
netlicensing.getItems().getItem().add(item);
205206

206-
final Map<String, String> propertyValues = new HashMap<String, String>(defaultPropertyValues);
207+
final Map<String, String> propertyValues = new HashMap<>(defaultPropertyValues);
207208
for (final String paramKey : formParams.keySet()) {
208209
propertyValues.put(paramKey, formParams.getFirst(paramKey));
209210
}
@@ -222,7 +223,7 @@ protected Response create(final MultivaluedMap<String, String> formParams,
222223

223224
/**
224225
* Defines common functionality for a "delete entity" service.
225-
*
226+
*
226227
* @param number
227228
* entity number
228229
* @param expectedNumber
@@ -240,7 +241,7 @@ protected Response delete(final String number, final String expectedNumber,
240241
}
241242

242243
// for testing purposes parameter "forceCascade" for "existing" entities should always be true if not absent
243-
final boolean hasForceCascade = queryParams != null && queryParams.containsKey(Constants.CASCADE);
244+
final boolean hasForceCascade = (queryParams != null) && queryParams.containsKey(Constants.CASCADE);
244245
if (hasForceCascade && !Boolean.valueOf(queryParams.getFirst(Constants.CASCADE))) {
245246
return unexpectedValueErrorResponse(Constants.CASCADE);
246247
}
@@ -250,14 +251,14 @@ protected Response delete(final String number, final String expectedNumber,
250251

251252
/**
252253
* Generates error response for the service mock
253-
*
254+
*
254255
* @param errorIdsAndMessages
255256
* array where every string with even index is exception ID and every string with odd index is
256257
* corresponding error message
257258
* @return response object
258259
*/
259260
protected final Response errorResponse(final String... errorIdsAndMessages) {
260-
if (errorIdsAndMessages.length % 2 != 0) {
261+
if ((errorIdsAndMessages.length % 2) != 0) {
261262
throw new IllegalArgumentException("Some exception ID doesn't have corresponding error message.");
262263
}
263264

@@ -272,7 +273,7 @@ protected final Response errorResponse(final String... errorIdsAndMessages) {
272273

273274
/**
274275
* Generates UnexpectedValueException response for the service mock
275-
*
276+
*
276277
* @param parameterName
277278
* parameter name
278279
* @return response object
@@ -292,7 +293,7 @@ protected void roundParamValueToTwoDecimalPlaces(final MultivaluedMap<String, St
292293
final String paramKey) {
293294
if (formParams.containsKey(paramKey)) {
294295
final String priceStr = formParams.getFirst(paramKey);
295-
final BigDecimal roundedPrice = new BigDecimal(priceStr).setScale(2, BigDecimal.ROUND_HALF_UP);
296+
final BigDecimal roundedPrice = new BigDecimal(priceStr).setScale(2, RoundingMode.HALF_UP);
296297
formParams.putSingle(paramKey, roundedPrice.toString());
297298
}
298299
}

NetLicensingClient/src/test/java/com/labs64/netlicensing/service/LicenseServiceTest.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
*/
1313
package com.labs64.netlicensing.service;
1414

15-
import static org.junit.Assert.assertEquals;
16-
import static org.junit.Assert.assertNotNull;
17-
import static org.junit.Assert.assertNull;
18-
import static org.junit.Assert.assertTrue;
19-
2015
import java.math.BigDecimal;
2116
import java.util.HashMap;
2217
import java.util.List;
@@ -28,9 +23,7 @@
2823
import javax.ws.rs.core.UriInfo;
2924

3025
import org.junit.BeforeClass;
31-
import org.junit.Rule;
3226
import org.junit.Test;
33-
import org.junit.rules.ExpectedException;
3427

3528
import com.labs64.netlicensing.domain.Constants;
3629
import com.labs64.netlicensing.domain.entity.License;
@@ -44,6 +37,12 @@
4437
import com.labs64.netlicensing.schema.context.Property;
4538
import com.labs64.netlicensing.util.JAXBUtils;
4639

40+
import static org.junit.Assert.assertEquals;
41+
import static org.junit.Assert.assertNotNull;
42+
import static org.junit.Assert.assertNull;
43+
import static org.junit.Assert.assertThrows;
44+
import static org.junit.Assert.assertTrue;
45+
4746
/**
4847
* Integration tests for {@link LicenseService}.
4948
*/
@@ -56,9 +55,6 @@ public class LicenseServiceTest extends BaseServiceTest {
5655

5756
private static Context context;
5857

59-
@Rule
60-
public ExpectedException thrown = ExpectedException.none();
61-
6258
@BeforeClass
6359
public static void setup() {
6460
context = createContext();
@@ -106,16 +102,18 @@ public void testCreateEmpty() throws Exception {
106102

107103
@Test
108104
public void testCreateWithoutLicenseeNumber() throws Exception {
109-
thrown.expect(ServiceException.class);
110-
thrown.expectMessage("MalformedRequestException: Licensee number is not provided");
111-
LicenseService.create(context, null, null, null, new LicenseImpl());
105+
final Exception e = assertThrows(ServiceException.class, () -> {
106+
LicenseService.create(context, null, null, null, new LicenseImpl());
107+
});
108+
assertEquals("MalformedRequestException: Licensee number is not provided", e.getMessage());
112109
}
113110

114111
@Test
115112
public void testCreateWithoutLicenseTemplateNumber() throws Exception {
116-
thrown.expect(ServiceException.class);
117-
thrown.expectMessage("MalformedRequestException: License template number is not provided");
118-
LicenseService.create(context, "L001-TEST", null, null, new LicenseImpl());
113+
final Exception e = assertThrows(ServiceException.class, () -> {
114+
LicenseService.create(context, "L001-TEST", null, null, new LicenseImpl());
115+
});
116+
assertEquals("MalformedRequestException: License template number is not provided", e.getMessage());
119117
}
120118

121119
@Test
@@ -174,9 +172,10 @@ public void testUpdate() throws Exception {
174172
public void testDelete() throws Exception {
175173
LicenseService.delete(context, "LC001-TEST", true);
176174

177-
thrown.expect(ServiceException.class);
178-
thrown.expectMessage("NotFoundException: Requested license does not exist");
179-
LicenseService.delete(context, "LC001-NONE", false);
175+
final Exception e = assertThrows(ServiceException.class, () -> {
176+
LicenseService.delete(context, "LC001-NONE", false);
177+
});
178+
assertEquals("NotFoundException: Requested license does not exist", e.getMessage());
180179
}
181180

182181
// *** NLIC test mock resource ***

0 commit comments

Comments
 (0)
0