### Question:
MetadataGenerator implements ApplicationContextAware { public EntityDescriptor generateMetadata() { if (signingKey == null) { signingKey = keyManager.getDefaultCredentialName(); } if (encryptionKey == null) { encryptionKey = keyManager.getDefaultCredentialName(); } boolean requestSigned = isRequestSigned(); boolean assertionSigned = isWantAssertionSigned(); boolean signMetadata = isSignMetadata(); Collection<String> includedBindings = getBindings(); Collection<String> includedNameID = getNameID(); String entityId = getEntityId(); String entityBaseURL = getEntityBaseURL(); String entityAlias = getEntityAlias(); if (entityId == null || entityBaseURL == null) { throw new RuntimeException("Required attributes weren't set"); } SAMLObjectBuilder<EntityDescriptor> builder = (SAMLObjectBuilder<EntityDescriptor>) builderFactory.getBuilder(EntityDescriptor.DEFAULT_ELEMENT_NAME); EntityDescriptor descriptor = builder.buildObject(); descriptor.setEntityID(entityId); descriptor.getRoleDescriptors().add(buildSPSSODescriptor(entityBaseURL, entityAlias, requestSigned, assertionSigned, includedBindings, includedNameID)); if (signMetadata) { try { signSAMLObject(descriptor, keyManager.getCredential(signingKey)); } catch (MessageEncodingException e) { throw new RuntimeException(e); } } return descriptor; }  void setApplicationContext(ApplicationContext applicationContext); void generateExtendedMetadata(ExtendedMetadata metadata); EntityDescriptor generateMetadata(); boolean isRequestSigned(); void setRequestSigned(boolean requestSigned); boolean isWantAssertionSigned(); void setWantAssertionSigned(boolean wantAssertionSigned); boolean isSignMetadata(); void setSignMetadata(boolean signMetadata); Collection<String> getNameID(); void setNameID(Collection<String> nameID); Collection<String> getBindings(); void setBindings(Collection<String> bindings); String getEntityBaseURL(); String getEntityAlias(); void setEntityAlias(String entityAlias); void setEntityBaseURL(String entityBaseURL); void setKeyManager(KeyManager keyManager); void setSigningKey(String signingKey); void setEncryptionKey(String encryptionKey); void setEntityId(String entityId); String getEntityId(); String getTlsKey(); void setTlsKey(String tlsKey); boolean isIncludeDiscovery(); void setIncludeDiscovery(boolean includeDiscovery);  }### Answer:
@Test public void testGenerateMetadata() { generator.setEntityBaseURL("http: generator.setEntityId("my_entity"); EntityDescriptor metadata = generator.generateMetadata(); assertEquals("my_entity", metadata.getEntityID()); SPSSODescriptor spssoDescriptor = metadata.getSPSSODescriptor(SAMLConstants.SAML20P_NS); assertNotNull(spssoDescriptor); assertTrue(spssoDescriptor.getExtensions().getUnknownXMLObjects().size() == 1); }