@Test public void testNullAndEmptyString() throws Exception { Signer signer = new Signer(new StringSignerSecretProvider("secret")); try { signer.sign(null); Assert.fail(); } catch (IllegalArgumentException ex) { } catch (Throwable ex) { Assert.fail(); } try { signer.sign(""); Assert.fail(); } catch (IllegalArgumentException ex) { } catch (Throwable ex) { Assert.fail(); } }
public synchronized String sign(String str) { if (str == null || str.length() == 0) { throw new IllegalArgumentException("NULL or empty string to sign"); } byte[] secret = secretProvider.getCurrentSecret(); String signature = computeSignature(secret, str); return str + SIGNATURE + signature; }
Signer { public synchronized String sign(String str) { if (str == null || str.length() == 0) { throw new IllegalArgumentException("NULL or empty string to sign"); } byte[] secret = secretProvider.getCurrentSecret(); String signature = computeSignature(secret, str); return str + SIGNATURE + signature; } }
Signer { public synchronized String sign(String str) { if (str == null || str.length() == 0) { throw new IllegalArgumentException("NULL or empty string to sign"); } byte[] secret = secretProvider.getCurrentSecret(); String signature = computeSignature(secret, str); return str + SIGNATURE + signature; } Signer(SignerSecretProvider secretProvider); }
Signer { public synchronized String sign(String str) { if (str == null || str.length() == 0) { throw new IllegalArgumentException("NULL or empty string to sign"); } byte[] secret = secretProvider.getCurrentSecret(); String signature = computeSignature(secret, str); return str + SIGNATURE + signature; } Signer(SignerSecretProvider secretProvider); synchronized String sign(String str); String verifyAndExtract(String signedStr); }
Signer { public synchronized String sign(String str) { if (str == null || str.length() == 0) { throw new IllegalArgumentException("NULL or empty string to sign"); } byte[] secret = secretProvider.getCurrentSecret(); String signature = computeSignature(secret, str); return str + SIGNATURE + signature; } Signer(SignerSecretProvider secretProvider); synchronized String sign(String str); String verifyAndExtract(String signedStr);  }