LicenseSupport { public static LicenseInformation parseSpdxExpression(String expression) { try { return LicenseSupport.fromSPDXExpression(expression); } catch (SpdxException e) { License unparsableExpression = new License(); unparsableExpression.setId(expression); return unparsableExpression; } }  static LicenseInformation mapLicenses(Collection<String> licenses); static LicenseInformation mapLicenses(Collection<String> licenses, LicenseOperator operator); static LicenseInformation fromSPDXExpression(String spdxExpressionString); static LicenseInformation fromSPDXExpression(SpdxExpression spdxExpression); static LicenseInformation parseSpdxExpression(String expression); static LicenseInformation fromSpdxLicenseReferenceExpression(SpdxLicenseReferenceExpression spdxLicenseReferenceExpression); static LicenseInformation fromSpdxLicenseIdExpression(SpdxLicenseIdExpression spdxLicenseIdExpression); static LicenseInformation fromSPDXCompoundExpression(SpdxCompoundExpression spdxCompoundExpression, LicenseStatement license);  }
@Test public void testParseSpdxExpression() { final LicenseInformation licenseInformation = LicenseSupport.parseSpdxExpression("BSD AND APACHE-2.0"); assertThat(licenseInformation.getLicenses().size()) .isEqualTo(2); LicenseStatement licenseStatement = (LicenseStatement) licenseInformation; assertThat(licenseStatement.getOp()) .isEqualTo(LicenseOperator.AND); }
@Test public void testParseSpdxExpressionWithNonValidExpression() { final String license = "APACHE-2.0 PLUS BSD"; final LicenseInformation licenseInformation = LicenseSupport.parseSpdxExpression(license); assertThat(licenseInformation.getLicenses().size()) .isEqualTo(1); assertThat(licenseInformation.getLicenses().iterator().next().getId()) .isEqualTo(license); }