1package io.flutter.plugin.common;
3import static org.junit.Assert.assertArrayEquals;
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertThrows;
6import static org.junit.Assert.assertTrue;
8import android.text.SpannableString;
9import androidx.test.ext.junit.runners.AndroidJUnit4;
10import java.nio.ByteBuffer;
11import java.util.ArrayList;
13import org.junit.runner.RunWith;
14import org.robolectric.annotation.Config;
17@RunWith(AndroidJUnit4.class)
21 private static final byte NULL = 0;
22 private static final byte TRUE = 1;
23 private static final byte FALSE = 2;
24 private static final byte INT = 3;
25 private static final byte LONG = 4;
26 private static final byte BIGINT = 5;
27 private static final byte DOUBLE = 6;
28 private static final byte STRING = 7;
29 private static final byte BYTE_ARRAY = 8;
30 private static final byte INT_ARRAY = 9;
31 private static final byte LONG_ARRAY = 10;
32 private static final byte DOUBLE_ARRAY = 11;
33 private static final byte LIST = 12;
34 private static final byte MAP = 13;
35 private static final byte FLOAT_ARRAY = 14;
45 ArrayList<Object> messageContent =
new ArrayList();
46 messageContent.add(
null);
49 ByteBuffer expected = ByteBuffer.allocateDirect(3);
50 expected.put(
new byte[] {LIST, 1, NULL});
52 assertEquals(expected,
message);
58 class ExampleNullObject {
60 public boolean equals(Object other) {
61 return other ==
null || other ==
this;
65 public int hashCode() {
74 ArrayList<Object> messageContent =
new ArrayList();
75 messageContent.add(
new ExampleNullObject());
78 ByteBuffer expected = ByteBuffer.allocateDirect(3);
79 expected.put(
new byte[] {LIST, 1, NULL});
81 assertEquals(expected,
message);
85 @SuppressWarnings(
"deprecation")
86 public
void itEncodesBooleans() {
90 ArrayList<Object> messageContent =
new ArrayList();
92 messageContent.add(
new Boolean(
true));
93 messageContent.add(
new Boolean(
false));
96 ByteBuffer expected = ByteBuffer.allocateDirect(4);
97 expected.put(
new byte[] {LIST, 2,
TRUE,
FALSE});
99 assertEquals(expected,
message);
106 float[] expectedValues =
new float[] {1.0f, 2.2f, 5.3f};
112 assertArrayEquals(expectedValues,
values, 0.01
f);
119 CharSequence cs =
new SpannableString(
"hello world");
125 assertEquals(
value,
"hello world");
128 private static class NotEncodable {
130 public String toString() {
131 return "not encodable";
138 NotEncodable notEncodable =
new NotEncodable();
139 Exception exception =
141 IllegalArgumentException.class,
143 codec.encodeMessage(notEncodable);
145 assertTrue(exception.getMessage().contains(
"NotEncodable"));
bool equals(SkDrawable *a, SkDrawable *b)
void itEncodesFloatArrays()
void itEncodesCharSequences()
void itEncodesNullObjects()
void itEncodesNullLiterals()
ByteBuffer encodeMessage(@Nullable Object message)
Object decodeMessage(@Nullable ByteBuffer message)