### Question:
JnaclSecretBox implements SecretBox { @Override public int cryptoBoxBeforenm(final byte[] output, final byte[] publicKey, final byte[] privateKey) { return curve25519xsalsa20poly1305.crypto_box_beforenm(output, publicKey, privateKey); }  @Override int cryptoBoxBeforenm(final byte[] output, final byte[] publicKey, final byte[] privateKey); @Override int cryptoBoxAfternm(final byte[] output, final byte[] message, final int messageLength, final byte[] nonce, final byte[] sharedKey); @Override int cryptoBoxOpenAfternm(final byte[] output, final byte[] message, final int messageLength, final byte[] nonce, final byte[] sharedKey); @Override int cryptoBoxKeypair(final byte[] publicKey, final byte[] privateKey);  }### Answer:
@Test public void sharedKeyUsingValidKeys() { final byte[] sharedKey = new byte[crypto_secretbox_BEFORENMBYTES]; final int success = this.secretBox.cryptoBoxBeforenm(sharedKey, publicKey, privateKey); assertThat(success).isEqualTo(0); }
@Test public void sharedKeyFailsIfOutputTooSmall() { final byte[] sharedKey = new byte[crypto_secretbox_BEFORENMBYTES-1]; final Throwable throwable = catchThrowable( () -> this.secretBox.cryptoBoxBeforenm(sharedKey, publicKey, privateKey) ); assertThat(throwable).isInstanceOf(ArrayIndexOutOfBoundsException.class); }
@Test public void sharedKeyFailsIfPublicKeyTooSmall() { final byte[] sharedKey = new byte[crypto_secretbox_BEFORENMBYTES]; final Throwable throwable = catchThrowable( () -> this.secretBox.cryptoBoxBeforenm( sharedKey, Arrays.copyOf(publicKey, publicKey.length-1), privateKey ) ); assertThat(throwable).isInstanceOf(ArrayIndexOutOfBoundsException.class); }
@Test public void sharedKeyFailsIfPrivateKeyTooSmall() { final byte[] sharedKey = new byte[crypto_secretbox_BEFORENMBYTES]; final Throwable throwable = catchThrowable( () -> this.secretBox.cryptoBoxBeforenm( sharedKey, publicKey, Arrays.copyOf(privateKey, privateKey.length-1) ) ); assertThat(throwable).isInstanceOf(ArrayIndexOutOfBoundsException.class); }