Skip to content

Commit

Permalink
Fix for null licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
menny committed Apr 30, 2021
1 parent 73ccad1 commit 6432906
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public enum Class {
public abstract String url();

public static License create(String name, String url) {
return new AutoValue_License(name, url);
return new AutoValue_License(nullToEmpty(name), nullToEmpty(url));
}

private static String nullToEmpty(String str) {
if (str == null) return "";
else return str;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,19 @@ public void testLicenseClassParsing() {

Assert.assertEquals(License.Class.permissive, LicenseTools.classFromLicenseName("WTFPL"));
}

@Test
public void testAutoValueLicenseCreate() {
Assert.assertEquals("License", License.create("License", "https://example.com/license.txt").name());
Assert.assertEquals("https://example.com/license.txt", License.create("License", "https://example.com/license.txt").url());


Assert.assertEquals("", License.create("", "whatever").name());
Assert.assertEquals("", License.create(null, "whatever").name());

Assert.assertEquals("", License.create("License", "").url());
Assert.assertEquals("", License.create("License", null).url());

Assert.assertEquals("", License.create(null, null).name());
}
}

0 comments on commit 6432906

Please sign in to comment.