CoderUtils { public static <T> byte[] encodeToByteArray(Coder<T> coder, T value) throws CoderException { return encodeToByteArray(coder, value, Coder.Context.OUTER); } private  CoderUtils(); static byte[] encodeToByteArray(Coder<T> coder, T value); static byte[] encodeToByteArray(Coder<T> coder, T value, Coder.Context context); static T decodeFromByteArray(Coder<T> coder, byte[] encodedValue); static T decodeFromByteArray(
      Coder<T> coder, byte[] encodedValue, Coder.Context context); static T clone(Coder<T> coder, T value); static String encodeToBase64(Coder<T> coder, T value); static T decodeFromBase64(Coder<T> coder, String encodedValue); @SuppressWarnings({"rawtypes", "unchecked"}) static TypeDescriptor getCodedType(TypeDescriptor coderDescriptor);  }
@Test public void testCoderExceptionPropagation() throws Exception { @SuppressWarnings("unchecked") Coder<String> crashingCoder = mock(Coder.class); doThrow(new CoderException("testing exception")) .when(crashingCoder) .encode(anyString(), any(OutputStream.class), any(Coder.Context.class)); expectedException.expect(CoderException.class); expectedException.expectMessage("testing exception"); CoderUtils.encodeToByteArray(crashingCoder, "hello"); }
@Test public void testClosingCoderFailsWhenEncodingToByteArray() throws Exception { expectedException.expect(UnsupportedOperationException.class); expectedException.expectMessage("Caller does not own the underlying"); CoderUtils.encodeToByteArray(new ClosingCoder(), "test-value"); }
@Test public void testClosingCoderFailsWhenEncodingToByteArrayInContext() throws Exception { expectedException.expect(UnsupportedOperationException.class); expectedException.expectMessage("Caller does not own the underlying"); CoderUtils.encodeToByteArray(new ClosingCoder(), "test-value", Context.NESTED); }