For IntelliJ IDEA and
Android Studio


@Test public void testClosingCoderFailsWhenEncoding() throws Exception { expectedException.expect(UnsupportedOperationException.class); expectedException.expectMessage("Caller does not own the underlying"); CoderProperties.encode(new ClosingCoder(), Context.NESTED, "test-value"); }
@Test public void testCoderWhichConsumesMoreBytesThanItProducesFail() throws IOException { try { BadCoderThatConsumesMoreBytes coder = new BadCoderThatConsumesMoreBytes(); byte[] bytes = CoderProperties.encode(coder, Context.NESTED, "TestData"); CoderProperties.decode(coder, Context.NESTED, bytes); Assert.fail("Expected Assertion Error"); } catch (AssertionError error) { assertThat(error.getMessage(), CoreMatchers.containsString("consumed bytes equal to encoded bytes")); } }
/** * Verifies that for the given {@code Coder<T>}, {@code Coder.Context}, and * values of type {@code T}, the values are equal if and only if the * encoded bytes are equal, in any {@code Coder.Context}. */ public static <T> void coderConsistentWithEqualsInContext( Coder<T> coder, Coder.Context context, T value1, T value2) throws Exception { assertEquals( value1.equals(value2), Arrays.equals( encode(coder, context, value1), encode(coder, context, value2))); }
private static <T> T decodeEncode(Coder<T> coder, Coder.Context context, T value) throws CoderException, IOException { return decode(coder, context, encode(coder, context, value)); }
/** * Verifies that for the given {@code Coder<T>}, {@code Coder.Context}, and values of * type {@code T}, if the values are equal then the encoded bytes are equal. */ public static <T> void coderDeterministicInContext( Coder<T> coder, Coder.Context context, T value1, T value2) throws Exception { try { coder.verifyDeterministic(); } catch (NonDeterministicException e) { fail("Expected that the coder is deterministic"); } assertThat("Expected that the passed in values are equal()", value1, equalTo(value2)); assertThat( encode(coder, context, value1), equalTo(encode(coder, context, value2))); }
/** * Verifies that for the given {@code Coder<T>}, {@code Coder.Context}, and * values of type {@code T}, the structural values are equal if and only if the * encoded bytes are equal, in any {@code Coder.Context}. */ public static <T> void structuralValueConsistentWithEqualsInContext( Coder<T> coder, Coder.Context context, T value1, T value2) throws Exception { assertEquals( coder.structuralValue(value1).equals(coder.structuralValue(value2)), Arrays.equals( encode(coder, context, value1), encode(coder, context, value2))); }
@Test public void testClosingCoderFailsWhenEncoding() throws Exception { expectedException.expect(UnsupportedOperationException.class); expectedException.expectMessage("Caller does not own the underlying"); CoderProperties.encode(new ClosingCoder(), Context.NESTED, "test-value"); }
@Test public void testCoderWhichConsumesMoreBytesThanItProducesFail() throws IOException { try { BadCoderThatConsumesMoreBytes coder = new BadCoderThatConsumesMoreBytes(); byte[] bytes = CoderProperties.encode(coder, Context.NESTED, "TestData"); CoderProperties.decode(coder, Context.NESTED, bytes); Assert.fail("Expected Assertion Error"); } catch (AssertionError error) { assertThat(error.getMessage(), CoreMatchers.containsString("consumed bytes equal to encoded bytes")); } }
/** * Verifies that for the given {@code Coder<T>}, {@code Coder.Context}, and * values of type {@code T}, the structural values are equal if and only if the * encoded bytes are equal, in any {@code Coder.Context}. */ public static <T> void structuralValueConsistentWithEqualsInContext( Coder<T> coder, Coder.Context context, T value1, T value2) throws Exception { assertEquals( coder.structuralValue(value1).equals(coder.structuralValue(value2)), Arrays.equals( encode(coder, context, value1), encode(coder, context, value2))); }
private static <T> T decodeEncode(Coder<T> coder, Coder.Context context, T value) throws CoderException, IOException { return decode(coder, context, encode(coder, context, value)); }
/** * Verifies that for the given {@code Coder<T>}, {@code Coder.Context}, and * values of type {@code T}, the values are equal if and only if the * encoded bytes are equal, in any {@code Coder.Context}. */ public static <T> void coderConsistentWithEqualsInContext( Coder<T> coder, Coder.Context context, T value1, T value2) throws Exception { assertEquals( value1.equals(value2), Arrays.equals( encode(coder, context, value1), encode(coder, context, value2))); }
/** * Verifies that for the given {@code Coder<T>}, {@code Coder.Context}, and values of * type {@code T}, if the values are equal then the encoded bytes are equal. */ public static <T> void coderDeterministicInContext( Coder<T> coder, Coder.Context context, T value1, T value2) throws Exception { try { coder.verifyDeterministic(); } catch (NonDeterministicException e) { fail("Expected that the coder is deterministic"); } assertThat("Expected that the passed in values are equal()", value1, equalTo(value2)); assertThat( encode(coder, context, value1), equalTo(encode(coder, context, value2))); }