public static <T> byte[] encodeToByteArray(Coder<T> coder, T value) throws CoderException {
    return encodeToByteArray(coder, value, Coder.Context.OUTER);
  }
@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");
  }