### Question:
SignatureBuilder implements Serializable { public abstract DataToSign buildDataToSign() throws SignerCertificateRequiredException, ContainerWithoutFilesException;  static SignatureBuilder aSignature(Container container); static void setSignatureBuilderForContainerType(
      String containerType,
      Class<T> signatureBuilderClass); static void removeCustomSignatureBuilders(); Signature invokeSigning(); abstract DataToSign buildDataToSign(); abstract Signature openAdESSignature(byte[] signatureDocument); SignatureBuilder withCity(String cityName); SignatureBuilder withStateOrProvince(String stateOrProvince); SignatureBuilder withPostalCode(String postalCode); SignatureBuilder withCountry(String country); SignatureBuilder withRoles(String... roles); SignatureBuilder withSignatureDigestAlgorithm(DigestAlgorithm digestAlgorithm); SignatureBuilder withSignatureProfile(SignatureProfile signatureProfile); SignatureBuilder withSigningCertificate(X509Certificate certificate); SignatureBuilder withSignatureId(String signatureId); SignatureBuilder withSignatureToken(SignatureToken signatureToken); SignatureBuilder withEncryptionAlgorithm(EncryptionAlgorithm encryptionAlgorithm); SignatureBuilder withOwnSignaturePolicy(Policy signaturePolicy);  }### Answer:
@Test public void signDocumentExternallyTwice() throws Exception { Container container = this.createNonEmptyContainer(); DataToSign dataToSign = TestDataBuilderUtil.buildDataToSign(container, "S0"); Signature signature = TestDataBuilderUtil.makeSignature(container, dataToSign); this.assertSignatureIsValid(signature); DataToSign dataToSign2 = TestDataBuilderUtil.buildDataToSign(container, "S1"); Signature signature2 = TestDataBuilderUtil.makeSignature(container, dataToSign2); this.assertSignatureIsValid(signature2); container.saveAsFile(this.getFileBy("bdoc")); }
@Test(expected = NotSupportedException.class) public void signUnknownContainerFormat_shouldThrowException() throws Exception { ContainerBuilder.setContainerImplementation("TEST-FORMAT", CustomContainer.class); Container container = TestDataBuilderUtil.createContainerWithFile(this.testFolder, "TEST-FORMAT"); TestDataBuilderUtil.buildDataToSign(container); }
@Test(expected = IllegalSignatureProfileException.class) public void asiceContainerWithoutSignatures_signWithTimemarkSignature_shouldFail() { Container container = buildContainer(ASICE, ASIC_WITH_NO_SIG); assertAsicEContainer(container); Assert.assertTrue(container.getSignatures().isEmpty()); buildDataToSign(container, SignatureProfile.LT_TM); }
@Test(expected = IllegalSignatureProfileException.class) public void asicEContainerWithTSSignature_signWithTimemarkSignature_shouldFail() { Container container = buildContainer(ASICE_WITH_TS_SIG); assertAsicEContainer(container); Assert.assertSame(1, container.getSignatures().size()); assertTimestampSignature(container.getSignatures().get(0)); buildDataToSign(container, SignatureProfile.LT_TM); }
@Test public void claimedSigningTimeInitializedDuringDataToSignBuilding() { Container container = ContainerBuilder.aContainer(BDOC).build(); container.addDataFile(new ByteArrayInputStream("something".getBytes()), "name", "text/plain"); long claimedSigningTimeLowerBound = new Date().getTime() / 1000 * 1000; DataToSign dataToSign = buildDataToSign(container, SignatureProfile.LT_TM); long claimedSigningTimeUpperBound = new Date().getTime() + 1000; long claimedSigningTime = dataToSign.getSignatureParameters().getClaimedSigningDate().getTime(); assertTrue(claimedSigningTime >= claimedSigningTimeLowerBound); assertTrue(claimedSigningTime <= claimedSigningTimeUpperBound); }