-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix StringIndexOutOfBoundsException for license (#122)
- Loading branch information
1 parent
576a55f
commit 133320e
Showing
2 changed files
with
58 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
get-metrics/src/test/java/org/sonatype/cs/getmetrics/util/ParseReasonsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.sonatype.cs.getmetrics.util; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import javax.json.Json; | ||
import javax.json.JsonArray; | ||
|
||
public class ParseReasonsTest { | ||
@Test | ||
void testEmptyLicenseString() { | ||
JsonArray reasons = Json.createArrayBuilder() | ||
.add(Json.createObjectBuilder() | ||
.add("reason", "")) | ||
.build(); | ||
|
||
String actualReason = ParseReasons.getLicense(reasons); | ||
Assertions.assertEquals("", actualReason); | ||
} | ||
|
||
@Test | ||
void testSingleLicenseString() { | ||
JsonArray reasons = Json.createArrayBuilder() | ||
.add(Json.createObjectBuilder() | ||
.add("reason", "(license)")) | ||
.build(); | ||
|
||
String actualReason = ParseReasons.getLicense(reasons); | ||
Assertions.assertEquals("license", actualReason); | ||
} | ||
|
||
@Test | ||
void testMultipltLicenseString() { | ||
JsonArray reasons = Json.createArrayBuilder() | ||
.add(Json.createObjectBuilder() | ||
.add("reason", "(license)") | ||
) | ||
.add(Json.createObjectBuilder() | ||
.add("reason", "(license2)") | ||
) | ||
.build(); | ||
|
||
String actualReason = ParseReasons.getLicense(reasons); | ||
Assertions.assertEquals("license:license2", actualReason); | ||
} | ||
} |