PkgFactory { Pkg createPackage( AttributeContext attributeContext, Attribute attribute) { Preconditions.checkNotNull(attribute); Preconditions.checkNotNull(attributeContext); Preconditions.checkState(attribute.getAttributeId() == AttributeId.PACKAGE); try { return new Pkg( getStringAttributeValue(attributeContext, attribute, AttributeId.PACKAGE_NAME), createVersion(attributeContext, attribute.getChildAttribute(AttributeId.PACKAGE_VERSION_MAJOR)), createArchitecture(attributeContext, attribute.getChildAttribute(AttributeId.PACKAGE_ARCHITECTURE)), getStringAttributeValue(attributeContext, attribute, AttributeId.PACKAGE_VENDOR), getChildAttributesAsStrings(attributeContext, attribute.getChildAttributes(AttributeId.PACKAGE_COPYRIGHT)), getChildAttributesAsStrings(attributeContext, attribute.getChildAttributes(AttributeId.PACKAGE_LICENSE)), getStringAttributeValue(attributeContext, attribute, AttributeId.PACKAGE_SUMMARY), getStringAttributeValue(attributeContext, attribute, AttributeId.PACKAGE_DESCRIPTION), tryCreateHomePagePkgUrl(attributeContext, attribute).orElse(null)); } catch(HpkException he) { throw new PkgException("unable to create a package owing to a problem with the hpk packaging",he); } }    }
@Test public void testCreatePackage() { Attribute attribute = createTestPackageAttributes(); PkgFactory pkgFactory = new PkgFactory(); AttributeContext attributeContext = new AttributeContext(); Pkg pkg = pkgFactory.createPackage( attributeContext, attribute); assertThat(pkg.getArchitecture()).isEqualTo(PkgArchitecture.X86); assertThat(pkg.getName()).isEqualTo("testpkg"); assertThat(pkg.getVendor()).isEqualTo("Test Vendor"); assertThat(pkg.getSummary()).isEqualTo("This is a test package summary"); assertThat(pkg.getDescription()).isEqualTo("This is a test package description"); assertThat(pkg.getHomePageUrl().getUrl()).isEqualTo("http: assertThat(pkg.getHomePageUrl().getUrlType()).isEqualTo(PkgUrlType.HOMEPAGE); assertThat(pkg.getVersion().getMajor()).isEqualTo("6"); assertThat(pkg.getVersion().getMinor()).isEqualTo("32"); assertThat(pkg.getVersion().getMicro()).isEqualTo("9"); assertThat(pkg.getVersion().getPreRelease()).isEqualTo("beta"); assertThat(pkg.getVersion().getRevision()).isEqualTo(8); assertThat(pkg.getCopyrights().stream().anyMatch(x -> x.equals("Some copyright A"))).isTrue(); assertThat(pkg.getLicenses().stream().anyMatch(x -> x.equals("Some license A"))).isTrue(); assertThat(pkg.getLicenses().stream().anyMatch(x -> x.equals("Some license B"))).isTrue(); }