Skip to content

Commit

Permalink
bug already in 3.1.0 was fixed is fixed here and also
Browse files Browse the repository at this point in the history
two tests that were not up-to-date (but fixed in 3.1.0) were updated
  • Loading branch information
verhas committed Jan 22, 2019
1 parent c6a4260 commit f9119da
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
30 changes: 16 additions & 14 deletions src/main/java/javax0/license3j/RevocableLicense.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
public class RevocableLicense {

final private static String REVOCATION_URL = "revocationUrl";
HttpHandler httpHandler = new HttpHandler();
private final License license;
HttpHandler httpHandler = new HttpHandler();

public RevocableLicense(License license) {
this.license = license;
Expand All @@ -36,8 +36,10 @@ public RevocableLicense(License license) {
* @throws MalformedURLException when the revocation url is not well formatted
*/
public URL getRevocationURL() throws MalformedURLException {
final var revocationURLTemplate = license.get(REVOCATION_URL).getString();
final String revocationURL;
final Feature revocationURLFeature = license.get(REVOCATION_URL);
final var revocationURLTemplate = revocationURLFeature == null ?
null :
revocationURLFeature.getString();
if (revocationURLTemplate != null) {
final var id = Optional.ofNullable(license.getLicenseId()).orElse(license.fingerprint());
if (id != null) {
Expand All @@ -50,6 +52,17 @@ public URL getRevocationURL() throws MalformedURLException {
}
}

/**
* Set the revocation URL. Using this method is discouraged in case the URL
* contains the <code>${licenseId}</code> place holder. In that case it is
* recommended to use the {@link #setRevocationURL(String)} method instead.
*
* @param url the revocation url
*/
public void setRevocationURL(final URL url) {
setRevocationURL(url.toString());
}

/**
* Set the revocation URL. This method accepts the url as a string that
* makes it possible to use a string that contains the
Expand All @@ -62,17 +75,6 @@ public void setRevocationURL(final String url) {
license.add(Feature.Create.stringFeature(REVOCATION_URL, url));
}

/**
* Set the revocation URL. Using this method is discouraged in case the URL
* contains the <code>${licenseId}</code> place holder. In that case it is
* recommended to use the {@link #setRevocationURL(String)} method instead.
*
* @param url the revocation url
*/
public void setRevocationURL(final URL url) {
setRevocationURL(url.toString());
}

/**
* Check if the license was revoked or not. For more information see the
* documentation of the method {@link #isRevoked(boolean)}. Calling this
Expand Down
32 changes: 16 additions & 16 deletions src/test/java/javax0/license3j/LicenseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public void licenseSerializeAndDeserialize() {
Assertions.assertEquals("Peter Verhas", restored.get("owner").getString());
Assertions.assertEquals(now, restored.get("expiry").getDate());
Assertions.assertEquals("expiry:DATE=2018-12-17 12:55:19.295\n" +
"owner:STRING=Peter Verhas\n" +
"template:STRING=<<null\n" +
"<<special template>>\n" +
"null\n" +
"title:STRING=<<B\n" +
"A license test, \n" +
"test license\n" +
"B\n", sut.toString());
"owner=Peter Verhas\n" +
"template=<<null\n" +
"<<special template>>\n" +
"null\n" +
"title=<<B\n" +
"A license test, \n" +
"test license\n" +
"B\n", sut.toString());
}

@Test
Expand All @@ -65,14 +65,14 @@ public void licenseStringifyAndDestringify() {
Assertions.assertEquals("Peter Verhas", restored.get("owner").getString());
Assertions.assertEquals(now, restored.get("expiry").getDate());
Assertions.assertEquals("expiry:DATE=2018-12-17 12:55:19.295\n" +
"owner:STRING=Peter Verhas\n" +
"template:STRING=<<null\n" +
"<<special template>>\n" +
"null\n" +
"title:STRING=<<B\n" +
"A license test, \n" +
"test license\n" +
"B\n", sut.toString());
"owner=Peter Verhas\n" +
"template=<<null\n" +
"<<special template>>\n" +
"null\n" +
"title=<<B\n" +
"A license test, \n" +
"test license\n" +
"B\n", sut.toString());
}

@Test
Expand Down

0 comments on commit f9119da

Please sign in to comment.