@Test public void testEncrypt() throws UnsupportedEncodingException { BytesEncryptor delegate = mock(BytesEncryptor.class); when(delegate.encrypt(any(byte[].class), anyInt(), any(byte[].class))).thenAnswer(new Answer<byte[]>() { @Override public byte[] answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); byte[] answer = (byte[]) args[0]; int offset = (Integer) args[1]; assertEquals(1, offset); return answer; } }); GzipEncryptor e = new GzipEncryptor(delegate); byte[] input1 = "Hello Hello Hello".getBytes("UTF8"); byte[] output1 = e.encrypt(input1, 1, new byte[1]); byte[] expectedOutput1 = input1; assertArrayEquals(expectedOutput1, output1); byte[] input2 = ("Hello AAAAA Hello AAAAA Hello AAAAA Hello AAAAA Hello AAAAA Hello AAAAA Hello " + "Hello AAAAA Hello AAAAA Hello AAAAA Hello AAAAA Hello AAAAA Hello AAAAA Hello").getBytes("UTF8"); byte[] output2 = e.encrypt(input2, 1, new byte[1]); byte[] expectedOutput2 = CryptoUnitUtils .hexToBytes("1f8b0800000000000000f348cdc9c957700401050f8ad9949b80c40600bbec62509b000000"); assertArrayEquals(expectedOutput2, output2); }
@Override public byte[] encrypt(byte[] input, int outputOffset, byte[] flags) { boolean compressed = input.length >= GZIP_THRESHOLD; if (compressed) { try { input = gzip(input); } catch (IOException e) { throw new CayenneCryptoException("Error compressing input", e); } } flags[0] = Header.setCompressed(flags[0], compressed); return delegate.encrypt(input, outputOffset, flags); }
GzipEncryptor implements BytesEncryptor { @Override public byte[] encrypt(byte[] input, int outputOffset, byte[] flags) { boolean compressed = input.length >= GZIP_THRESHOLD; if (compressed) { try { input = gzip(input); } catch (IOException e) { throw new CayenneCryptoException("Error compressing input", e); } } flags[0] = Header.setCompressed(flags[0], compressed); return delegate.encrypt(input, outputOffset, flags); } }
GzipEncryptor implements BytesEncryptor { @Override public byte[] encrypt(byte[] input, int outputOffset, byte[] flags) { boolean compressed = input.length >= GZIP_THRESHOLD; if (compressed) { try { input = gzip(input); } catch (IOException e) { throw new CayenneCryptoException("Error compressing input", e); } } flags[0] = Header.setCompressed(flags[0], compressed); return delegate.encrypt(input, outputOffset, flags); } GzipEncryptor(BytesEncryptor delegate); }
GzipEncryptor implements BytesEncryptor { @Override public byte[] encrypt(byte[] input, int outputOffset, byte[] flags) { boolean compressed = input.length >= GZIP_THRESHOLD; if (compressed) { try { input = gzip(input); } catch (IOException e) { throw new CayenneCryptoException("Error compressing input", e); } } flags[0] = Header.setCompressed(flags[0], compressed); return delegate.encrypt(input, outputOffset, flags); } GzipEncryptor(BytesEncryptor delegate); @Override byte[] encrypt(byte[] input, int outputOffset, byte[] flags); }
GzipEncryptor implements BytesEncryptor { @Override public byte[] encrypt(byte[] input, int outputOffset, byte[] flags) { boolean compressed = input.length >= GZIP_THRESHOLD; if (compressed) { try { input = gzip(input); } catch (IOException e) { throw new CayenneCryptoException("Error compressing input", e); } } flags[0] = Header.setCompressed(flags[0], compressed); return delegate.encrypt(input, outputOffset, flags); } GzipEncryptor(BytesEncryptor delegate); @Override byte[] encrypt(byte[] input, int outputOffset, byte[] flags);  }