PeppolIdentifierFactory implements IIdentifierFactory { @Override public boolean isProcessIdentifierValueValid (@Nullable final String sValue) { final int nLength = StringHelper.getLength (sValue); if (nLength == 0 || nLength > PeppolIdentifierHelper.MAX_PROCESS_VALUE_LENGTH) return false; return PeppolIdentifierHelper.areCharsetChecksDisabled () || StandardCharsets.ISO_8859_1.newEncoder ().canEncode (sValue); } PeppolIdentifierFactory(); @Override boolean isDocumentTypeIdentifierSchemeMandatory(); @Nonnull @Override String getDefaultDocumentTypeIdentifierScheme(); @Override boolean isDocumentTypeIdentifierSchemeValid(@Nullable final String sScheme); @Override boolean isDocumentTypeIdentifierValueValid(@Nullable final String sValue); @Nullable @Override PeppolDocumentTypeIdentifier createDocumentTypeIdentifierWithDefaultScheme(@Nullable final String sValue); @Nullable PeppolDocumentTypeIdentifier createDocumentTypeIdentifier(@Nullable final String sScheme, @Nullable final String sValue); @Override boolean isParticipantIdentifierSchemeMandatory(); @Nonnull @Override String getDefaultParticipantIdentifierScheme(); @Override boolean isParticipantIdentifierCaseInsensitive(@Nullable final String sScheme); @Override boolean isParticipantIdentifierSchemeValid(@Nullable final String sScheme); @Override boolean isParticipantIdentifierValueValid(@Nullable final String sValue); @Nullable @Override PeppolParticipantIdentifier createParticipantIdentifierWithDefaultScheme(@Nullable final String sValue); @Nullable PeppolParticipantIdentifier createParticipantIdentifier(@Nullable final String sScheme, @Nullable final String sValue); @Nonnull @Override String getDefaultProcessIdentifierScheme(); @Override boolean isProcessIdentifierSchemeValid(@Nullable final String sScheme); @Override boolean isProcessIdentifierValueValid(@Nullable final String sValue); @Nullable @Override PeppolProcessIdentifier createProcessIdentifierWithDefaultScheme(@Nullable final String sValue); @Nullable PeppolProcessIdentifier createProcessIdentifier(@Nullable final String sScheme, @Nullable final String sValue); @Override String toString(); static final PeppolIdentifierFactory INSTANCE; }
@Test public void testIsValidProcessIdentifierValue () { assertFalse (PeppolIdentifierFactory.INSTANCE.isProcessIdentifierValueValid (null)); assertFalse (PeppolIdentifierFactory.INSTANCE.isProcessIdentifierValueValid ("")); assertTrue (PeppolIdentifierFactory.INSTANCE.isProcessIdentifierValueValid ("proc1")); assertTrue (PeppolIdentifierFactory.INSTANCE.isProcessIdentifierValueValid ("proc2 ")); assertTrue (PeppolIdentifierFactory.INSTANCE.isProcessIdentifierValueValid (StringHelper.getRepeated ('a', PeppolIdentifierHelper.MAX_PROCESS_VALUE_LENGTH))); assertFalse (PeppolIdentifierFactory.INSTANCE.isProcessIdentifierValueValid (StringHelper.getRepeated ('a', PeppolIdentifierHelper.MAX_PROCESS_VALUE_LENGTH + 1))); }