mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19:21 +08:00
Use AssertJ instead of JUnit assertions.
This commit is contained in:
@@ -19,156 +19,156 @@ import java.io.IOException;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static com.squareup.moshi.TestUtil.newReader;
|
import static com.squareup.moshi.TestUtil.newReader;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public final class JsonReaderPathTest {
|
public final class JsonReaderPathTest {
|
||||||
@Test public void path() throws IOException {
|
@Test public void path() throws IOException {
|
||||||
JsonReader reader = newReader("{\"a\":[2,true,false,null,\"b\",{\"c\":\"d\"},[3]]}");
|
JsonReader reader = newReader("{\"a\":[2,true,false,null,\"b\",{\"c\":\"d\"},[3]]}");
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
reader.beginObject();
|
reader.beginObject();
|
||||||
assertEquals("$.", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.");
|
||||||
reader.nextName();
|
reader.nextName();
|
||||||
assertEquals("$.a", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a");
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
assertEquals("$.a[0]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a[0]");
|
||||||
reader.nextInt();
|
reader.nextInt();
|
||||||
assertEquals("$.a[1]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a[1]");
|
||||||
reader.nextBoolean();
|
reader.nextBoolean();
|
||||||
assertEquals("$.a[2]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a[2]");
|
||||||
reader.nextBoolean();
|
reader.nextBoolean();
|
||||||
assertEquals("$.a[3]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a[3]");
|
||||||
reader.nextNull();
|
reader.nextNull();
|
||||||
assertEquals("$.a[4]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a[4]");
|
||||||
reader.nextString();
|
reader.nextString();
|
||||||
assertEquals("$.a[5]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a[5]");
|
||||||
reader.beginObject();
|
reader.beginObject();
|
||||||
assertEquals("$.a[5].", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a[5].");
|
||||||
reader.nextName();
|
reader.nextName();
|
||||||
assertEquals("$.a[5].c", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a[5].c");
|
||||||
reader.nextString();
|
reader.nextString();
|
||||||
assertEquals("$.a[5].c", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a[5].c");
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals("$.a[6]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a[6]");
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
assertEquals("$.a[6][0]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a[6][0]");
|
||||||
reader.nextInt();
|
reader.nextInt();
|
||||||
assertEquals("$.a[6][1]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a[6][1]");
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals("$.a[7]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a[7]");
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals("$.a", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a");
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void arrayOfObjects() throws IOException {
|
@Test public void arrayOfObjects() throws IOException {
|
||||||
JsonReader reader = newReader("[{},{},{}]");
|
JsonReader reader = newReader("[{},{},{}]");
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
assertEquals("$[0]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[0]");
|
||||||
reader.beginObject();
|
reader.beginObject();
|
||||||
assertEquals("$[0].", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[0].");
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals("$[1]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[1]");
|
||||||
reader.beginObject();
|
reader.beginObject();
|
||||||
assertEquals("$[1].", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[1].");
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals("$[2]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[2]");
|
||||||
reader.beginObject();
|
reader.beginObject();
|
||||||
assertEquals("$[2].", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[2].");
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals("$[3]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[3]");
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void arrayOfArrays() throws IOException {
|
@Test public void arrayOfArrays() throws IOException {
|
||||||
JsonReader reader = newReader("[[],[],[]]");
|
JsonReader reader = newReader("[[],[],[]]");
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
assertEquals("$[0]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[0]");
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
assertEquals("$[0][0]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[0][0]");
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals("$[1]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[1]");
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
assertEquals("$[1][0]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[1][0]");
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals("$[2]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[2]");
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
assertEquals("$[2][0]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[2][0]");
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals("$[3]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[3]");
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void objectPath() throws IOException {
|
@Test public void objectPath() throws IOException {
|
||||||
JsonReader reader = newReader("{\"a\":1,\"b\":2}");
|
JsonReader reader = newReader("{\"a\":1,\"b\":2}");
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
|
|
||||||
reader.peek();
|
reader.peek();
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
reader.beginObject();
|
reader.beginObject();
|
||||||
assertEquals("$.", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.");
|
||||||
|
|
||||||
reader.peek();
|
reader.peek();
|
||||||
assertEquals("$.", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.");
|
||||||
reader.nextName();
|
reader.nextName();
|
||||||
assertEquals("$.a", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a");
|
||||||
|
|
||||||
reader.peek();
|
reader.peek();
|
||||||
assertEquals("$.a", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a");
|
||||||
reader.nextInt();
|
reader.nextInt();
|
||||||
assertEquals("$.a", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a");
|
||||||
|
|
||||||
reader.peek();
|
reader.peek();
|
||||||
assertEquals("$.a", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.a");
|
||||||
reader.nextName();
|
reader.nextName();
|
||||||
assertEquals("$.b", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.b");
|
||||||
|
|
||||||
reader.peek();
|
reader.peek();
|
||||||
assertEquals("$.b", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.b");
|
||||||
reader.nextInt();
|
reader.nextInt();
|
||||||
assertEquals("$.b", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.b");
|
||||||
|
|
||||||
reader.peek();
|
reader.peek();
|
||||||
assertEquals("$.b", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.b");
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
|
|
||||||
reader.peek();
|
reader.peek();
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
reader.close();
|
reader.close();
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void arrayPath() throws IOException {
|
@Test public void arrayPath() throws IOException {
|
||||||
JsonReader reader = newReader("[1,2]");
|
JsonReader reader = newReader("[1,2]");
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
|
|
||||||
reader.peek();
|
reader.peek();
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
assertEquals("$[0]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[0]");
|
||||||
|
|
||||||
reader.peek();
|
reader.peek();
|
||||||
assertEquals("$[0]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[0]");
|
||||||
reader.nextInt();
|
reader.nextInt();
|
||||||
assertEquals("$[1]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[1]");
|
||||||
|
|
||||||
reader.peek();
|
reader.peek();
|
||||||
assertEquals("$[1]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[1]");
|
||||||
reader.nextInt();
|
reader.nextInt();
|
||||||
assertEquals("$[2]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[2]");
|
||||||
|
|
||||||
reader.peek();
|
reader.peek();
|
||||||
assertEquals("$[2]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[2]");
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
|
|
||||||
reader.peek();
|
reader.peek();
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
reader.close();
|
reader.close();
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void multipleTopLevelValuesInOneDocument() throws IOException {
|
@Test public void multipleTopLevelValuesInOneDocument() throws IOException {
|
||||||
@@ -176,10 +176,10 @@ public final class JsonReaderPathTest {
|
|||||||
reader.setLenient(true);
|
reader.setLenient(true);
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
assertEquals("$", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void skipArrayElements() throws IOException {
|
@Test public void skipArrayElements() throws IOException {
|
||||||
@@ -187,14 +187,14 @@ public final class JsonReaderPathTest {
|
|||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
reader.skipValue();
|
reader.skipValue();
|
||||||
reader.skipValue();
|
reader.skipValue();
|
||||||
assertEquals("$[2]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[2]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void skipObjectNames() throws IOException {
|
@Test public void skipObjectNames() throws IOException {
|
||||||
JsonReader reader = newReader("{\"a\":1}");
|
JsonReader reader = newReader("{\"a\":1}");
|
||||||
reader.beginObject();
|
reader.beginObject();
|
||||||
reader.skipValue();
|
reader.skipValue();
|
||||||
assertEquals("$.null", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void skipObjectValues() throws IOException {
|
@Test public void skipObjectValues() throws IOException {
|
||||||
@@ -202,15 +202,15 @@ public final class JsonReaderPathTest {
|
|||||||
reader.beginObject();
|
reader.beginObject();
|
||||||
reader.nextName();
|
reader.nextName();
|
||||||
reader.skipValue();
|
reader.skipValue();
|
||||||
assertEquals("$.null", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.null");
|
||||||
reader.nextName();
|
reader.nextName();
|
||||||
assertEquals("$.b", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$.b");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void skipNestedStructures() throws IOException {
|
@Test public void skipNestedStructures() throws IOException {
|
||||||
JsonReader reader = newReader("[[1,2,3],4]");
|
JsonReader reader = newReader("[[1,2,3],4]");
|
||||||
reader.beginArray();
|
reader.beginArray();
|
||||||
reader.skipValue();
|
reader.skipValue();
|
||||||
assertEquals("$[1]", reader.getPath());
|
assertThat(reader.getPath()).isEqualTo("$[1]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -21,7 +21,7 @@ import java.math.BigInteger;
|
|||||||
import okio.Buffer;
|
import okio.Buffer;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public final class JsonWriterTest {
|
public final class JsonWriterTest {
|
||||||
@@ -33,7 +33,7 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.nullValue();
|
jsonWriter.nullValue();
|
||||||
jsonWriter.endObject();
|
jsonWriter.endObject();
|
||||||
jsonWriter.close();
|
jsonWriter.close();
|
||||||
assertEquals("{}", buffer.readUtf8());
|
assertThat(buffer.readUtf8()).isEqualTo("{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void nullsValuesSerializedWhenConfigured() throws IOException {
|
@Test public void nullsValuesSerializedWhenConfigured() throws IOException {
|
||||||
@@ -45,7 +45,7 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.nullValue();
|
jsonWriter.nullValue();
|
||||||
jsonWriter.endObject();
|
jsonWriter.endObject();
|
||||||
jsonWriter.close();
|
jsonWriter.close();
|
||||||
assertEquals("{\"a\":null}", buffer.readUtf8());
|
assertThat(buffer.readUtf8()).isEqualTo("{\"a\":null}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void wrongTopLevelType() throws IOException {
|
@Test public void wrongTopLevelType() throws IOException {
|
||||||
@@ -147,7 +147,7 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.name("a");
|
jsonWriter.name("a");
|
||||||
jsonWriter.value((String) null);
|
jsonWriter.value((String) null);
|
||||||
jsonWriter.endObject();
|
jsonWriter.endObject();
|
||||||
assertEquals("{\"a\":null}", buffer.readUtf8());
|
assertThat(buffer.readUtf8()).isEqualTo("{\"a\":null}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void nonFiniteDoubles() throws IOException {
|
@Test public void nonFiniteDoubles() throws IOException {
|
||||||
@@ -207,7 +207,7 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.value(Math.E);
|
jsonWriter.value(Math.E);
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
jsonWriter.close();
|
jsonWriter.close();
|
||||||
assertEquals("[-0.0,"
|
assertThat(buffer.readUtf8()).isEqualTo("[-0.0,"
|
||||||
+ "1.0,"
|
+ "1.0,"
|
||||||
+ "1.7976931348623157E308,"
|
+ "1.7976931348623157E308,"
|
||||||
+ "4.9E-324,"
|
+ "4.9E-324,"
|
||||||
@@ -215,7 +215,7 @@ public final class JsonWriterTest {
|
|||||||
+ "-0.5,"
|
+ "-0.5,"
|
||||||
+ "2.2250738585072014E-308,"
|
+ "2.2250738585072014E-308,"
|
||||||
+ "3.141592653589793,"
|
+ "3.141592653589793,"
|
||||||
+ "2.718281828459045]", buffer.readUtf8());
|
+ "2.718281828459045]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void longs() throws IOException {
|
@Test public void longs() throws IOException {
|
||||||
@@ -229,11 +229,11 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.value(Long.MAX_VALUE);
|
jsonWriter.value(Long.MAX_VALUE);
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
jsonWriter.close();
|
jsonWriter.close();
|
||||||
assertEquals("[0,"
|
assertThat(buffer.readUtf8()).isEqualTo("[0,"
|
||||||
+ "1,"
|
+ "1,"
|
||||||
+ "-1,"
|
+ "-1,"
|
||||||
+ "-9223372036854775808,"
|
+ "-9223372036854775808,"
|
||||||
+ "9223372036854775807]", buffer.readUtf8());
|
+ "9223372036854775807]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void numbers() throws IOException {
|
@Test public void numbers() throws IOException {
|
||||||
@@ -246,10 +246,10 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.value(new BigDecimal("3.141592653589793238462643383"));
|
jsonWriter.value(new BigDecimal("3.141592653589793238462643383"));
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
jsonWriter.close();
|
jsonWriter.close();
|
||||||
assertEquals("[0,"
|
assertThat(buffer.readUtf8()).isEqualTo("[0,"
|
||||||
+ "9223372036854775808,"
|
+ "9223372036854775808,"
|
||||||
+ "-9223372036854775809,"
|
+ "-9223372036854775809,"
|
||||||
+ "3.141592653589793238462643383]", buffer.readUtf8());
|
+ "3.141592653589793238462643383]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void booleans() throws IOException {
|
@Test public void booleans() throws IOException {
|
||||||
@@ -259,7 +259,7 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.value(true);
|
jsonWriter.value(true);
|
||||||
jsonWriter.value(false);
|
jsonWriter.value(false);
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
assertEquals("[true,false]", buffer.readUtf8());
|
assertThat(buffer.readUtf8()).isEqualTo("[true,false]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void nulls() throws IOException {
|
@Test public void nulls() throws IOException {
|
||||||
@@ -268,7 +268,7 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.beginArray();
|
jsonWriter.beginArray();
|
||||||
jsonWriter.nullValue();
|
jsonWriter.nullValue();
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
assertEquals("[null]", buffer.readUtf8());
|
assertThat(buffer.readUtf8()).isEqualTo("[null]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void strings() throws IOException {
|
@Test public void strings() throws IOException {
|
||||||
@@ -294,7 +294,7 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.value("\0");
|
jsonWriter.value("\0");
|
||||||
jsonWriter.value("\u0019");
|
jsonWriter.value("\u0019");
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
assertEquals("[\"a\","
|
assertThat(buffer.readUtf8()).isEqualTo("[\"a\","
|
||||||
+ "\"a\\\"\","
|
+ "\"a\\\"\","
|
||||||
+ "\"\\\"\","
|
+ "\"\\\"\","
|
||||||
+ "\":\","
|
+ "\":\","
|
||||||
@@ -311,7 +311,7 @@ public final class JsonWriterTest {
|
|||||||
+ "\"[\","
|
+ "\"[\","
|
||||||
+ "\"]\","
|
+ "\"]\","
|
||||||
+ "\"\\u0000\","
|
+ "\"\\u0000\","
|
||||||
+ "\"\\u0019\"]", buffer.readUtf8());
|
+ "\"\\u0019\"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void unicodeLineBreaksEscaped() throws IOException {
|
@Test public void unicodeLineBreaksEscaped() throws IOException {
|
||||||
@@ -320,7 +320,7 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.beginArray();
|
jsonWriter.beginArray();
|
||||||
jsonWriter.value("\u2028 \u2029");
|
jsonWriter.value("\u2028 \u2029");
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
assertEquals("[\"\\u2028 \\u2029\"]", buffer.readUtf8());
|
assertThat(buffer.readUtf8()).isEqualTo("[\"\\u2028 \\u2029\"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void emptyArray() throws IOException {
|
@Test public void emptyArray() throws IOException {
|
||||||
@@ -328,7 +328,7 @@ public final class JsonWriterTest {
|
|||||||
JsonWriter jsonWriter = new JsonWriter(buffer);
|
JsonWriter jsonWriter = new JsonWriter(buffer);
|
||||||
jsonWriter.beginArray();
|
jsonWriter.beginArray();
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
assertEquals("[]", buffer.readUtf8());
|
assertThat(buffer.readUtf8()).isEqualTo("[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void emptyObject() throws IOException {
|
@Test public void emptyObject() throws IOException {
|
||||||
@@ -336,7 +336,7 @@ public final class JsonWriterTest {
|
|||||||
JsonWriter jsonWriter = new JsonWriter(buffer);
|
JsonWriter jsonWriter = new JsonWriter(buffer);
|
||||||
jsonWriter.beginObject();
|
jsonWriter.beginObject();
|
||||||
jsonWriter.endObject();
|
jsonWriter.endObject();
|
||||||
assertEquals("{}", buffer.readUtf8());
|
assertThat(buffer.readUtf8()).isEqualTo("{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void objectsInArrays() throws IOException {
|
@Test public void objectsInArrays() throws IOException {
|
||||||
@@ -352,8 +352,8 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.name("d").value(true);
|
jsonWriter.name("d").value(true);
|
||||||
jsonWriter.endObject();
|
jsonWriter.endObject();
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
assertEquals("[{\"a\":5,\"b\":false},"
|
assertThat(buffer.readUtf8()).isEqualTo("[{\"a\":5,\"b\":false},"
|
||||||
+ "{\"c\":6,\"d\":true}]", buffer.readUtf8());
|
+ "{\"c\":6,\"d\":true}]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void arraysInObjects() throws IOException {
|
@Test public void arraysInObjects() throws IOException {
|
||||||
@@ -371,8 +371,8 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.value(true);
|
jsonWriter.value(true);
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
jsonWriter.endObject();
|
jsonWriter.endObject();
|
||||||
assertEquals("{\"a\":[5,false],"
|
assertThat(buffer.readUtf8()).isEqualTo("{\"a\":[5,false],"
|
||||||
+ "\"b\":[6,true]}", buffer.readUtf8());
|
+ "\"b\":[6,true]}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void deepNestingArrays() throws IOException {
|
@Test public void deepNestingArrays() throws IOException {
|
||||||
@@ -384,7 +384,7 @@ public final class JsonWriterTest {
|
|||||||
for (int i = 0; i < 20; i++) {
|
for (int i = 0; i < 20; i++) {
|
||||||
jsonWriter.endArray();
|
jsonWriter.endArray();
|
||||||
}
|
}
|
||||||
assertEquals("[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]", buffer.readUtf8());
|
assertThat(buffer.readUtf8()).isEqualTo("[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void deepNestingObjects() throws IOException {
|
@Test public void deepNestingObjects() throws IOException {
|
||||||
@@ -399,9 +399,10 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.endObject();
|
jsonWriter.endObject();
|
||||||
}
|
}
|
||||||
jsonWriter.endObject();
|
jsonWriter.endObject();
|
||||||
assertEquals("{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":"
|
assertThat(buffer.readUtf8()).isEqualTo(
|
||||||
|
"{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":"
|
||||||
+ "{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{"
|
+ "{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{"
|
||||||
+ "}}}}}}}}}}}}}}}}}}}}}", buffer.readUtf8());
|
+ "}}}}}}}}}}}}}}}}}}}}}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void repeatedName() throws IOException {
|
@Test public void repeatedName() throws IOException {
|
||||||
@@ -412,7 +413,7 @@ public final class JsonWriterTest {
|
|||||||
jsonWriter.name("a").value(false);
|
jsonWriter.name("a").value(false);
|
||||||
jsonWriter.endObject();
|
jsonWriter.endObject();
|
||||||
// JsonWriter doesn't attempt to detect duplicate names
|
// JsonWriter doesn't attempt to detect duplicate names
|
||||||
assertEquals("{\"a\":true,\"a\":false}", buffer.readUtf8());
|
assertThat(buffer.readUtf8()).isEqualTo("{\"a\":true,\"a\":false}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void prettyPrintObject() throws IOException {
|
@Test public void prettyPrintObject() throws IOException {
|
||||||
@@ -450,7 +451,7 @@ public final class JsonWriterTest {
|
|||||||
+ " \"i\": 9.0\n"
|
+ " \"i\": 9.0\n"
|
||||||
+ " }\n"
|
+ " }\n"
|
||||||
+ "}";
|
+ "}";
|
||||||
assertEquals(expected, buffer.readUtf8());
|
assertThat(buffer.readUtf8()).isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void prettyPrintArray() throws IOException {
|
@Test public void prettyPrintArray() throws IOException {
|
||||||
@@ -487,7 +488,7 @@ public final class JsonWriterTest {
|
|||||||
+ " 9.0\n"
|
+ " 9.0\n"
|
||||||
+ " ]\n"
|
+ " ]\n"
|
||||||
+ "]";
|
+ "]";
|
||||||
assertEquals(expected, buffer.readUtf8());
|
assertThat(buffer.readUtf8()).isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void lenientWriterPermitsMultipleTopLevelValues() throws IOException {
|
@Test public void lenientWriterPermitsMultipleTopLevelValues() throws IOException {
|
||||||
@@ -499,7 +500,7 @@ public final class JsonWriterTest {
|
|||||||
writer.beginArray();
|
writer.beginArray();
|
||||||
writer.endArray();
|
writer.endArray();
|
||||||
writer.close();
|
writer.close();
|
||||||
assertEquals("[][]", buffer.readUtf8());
|
assertThat(buffer.readUtf8()).isEqualTo("[][]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void strictWriterDoesNotPermitMultipleTopLevelValues() throws IOException {
|
@Test public void strictWriterDoesNotPermitMultipleTopLevelValues() throws IOException {
|
||||||
|
@@ -18,18 +18,12 @@ package com.squareup.moshi;
|
|||||||
import com.squareup.moshi.LinkedHashTreeMap.AvlBuilder;
|
import com.squareup.moshi.LinkedHashTreeMap.AvlBuilder;
|
||||||
import com.squareup.moshi.LinkedHashTreeMap.AvlIterator;
|
import com.squareup.moshi.LinkedHashTreeMap.AvlIterator;
|
||||||
import com.squareup.moshi.LinkedHashTreeMap.Node;
|
import com.squareup.moshi.LinkedHashTreeMap.Node;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public final class LinkedHashTreeMapTest {
|
public final class LinkedHashTreeMapTest {
|
||||||
@@ -38,8 +32,8 @@ public final class LinkedHashTreeMapTest {
|
|||||||
map.put("a", "android");
|
map.put("a", "android");
|
||||||
map.put("c", "cola");
|
map.put("c", "cola");
|
||||||
map.put("b", "bbq");
|
map.put("b", "bbq");
|
||||||
assertIterationOrder(map.keySet(), "a", "c", "b");
|
assertThat(map.keySet()).containsExactly("a", "c", "b");
|
||||||
assertIterationOrder(map.values(), "android", "cola", "bbq");
|
assertThat(map.values()).containsExactly("android", "cola", "bbq");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void removeRootDoesNotDoubleUnlink() {
|
@Test public void removeRootDoesNotDoubleUnlink() {
|
||||||
@@ -52,7 +46,7 @@ public final class LinkedHashTreeMapTest {
|
|||||||
it.next();
|
it.next();
|
||||||
it.next();
|
it.next();
|
||||||
it.remove();
|
it.remove();
|
||||||
assertIterationOrder(map.keySet(), "a", "c");
|
assertThat(map.keySet()).containsExactly("a", "c");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void putNullKeyFails() {
|
@Test public void putNullKeyFails() {
|
||||||
@@ -73,34 +67,34 @@ public final class LinkedHashTreeMapTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test public void ContainsNonComparableKeyReturnsFalse() {
|
@Test public void ContainsNonComparableKeyReturnsFalse() {
|
||||||
LinkedHashTreeMap<String, String> map = new LinkedHashTreeMap<>();
|
LinkedHashTreeMap<Object, String> map = new LinkedHashTreeMap<>();
|
||||||
map.put("a", "android");
|
map.put("a", "android");
|
||||||
assertFalse(map.containsKey(new Object()));
|
assertThat(map).doesNotContainKey(new Object());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void containsNullKeyIsAlwaysFalse() {
|
@Test public void containsNullKeyIsAlwaysFalse() {
|
||||||
LinkedHashTreeMap<String, String> map = new LinkedHashTreeMap<>();
|
LinkedHashTreeMap<String, String> map = new LinkedHashTreeMap<>();
|
||||||
map.put("a", "android");
|
map.put("a", "android");
|
||||||
assertFalse(map.containsKey(null));
|
assertThat(map).doesNotContainKey(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void putOverrides() throws Exception {
|
@Test public void putOverrides() throws Exception {
|
||||||
LinkedHashTreeMap<String, String> map = new LinkedHashTreeMap<>();
|
LinkedHashTreeMap<String, String> map = new LinkedHashTreeMap<>();
|
||||||
assertNull(map.put("d", "donut"));
|
assertThat(map.put("d", "donut")).isNull();
|
||||||
assertNull(map.put("e", "eclair"));
|
assertThat(map.put("e", "eclair")).isNull();
|
||||||
assertNull(map.put("f", "froyo"));
|
assertThat(map.put("f", "froyo")).isNull();
|
||||||
assertEquals(3, map.size());
|
assertThat(map.size()).isEqualTo(3);
|
||||||
|
|
||||||
assertEquals("donut", map.get("d"));
|
assertThat(map.get("d")).isEqualTo("donut");
|
||||||
assertEquals("donut", map.put("d", "done"));
|
assertThat(map.put("d", "done")).isEqualTo("donut");
|
||||||
assertEquals(3, map.size());
|
assertThat(map).hasSize(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void emptyStringValues() {
|
@Test public void emptyStringValues() {
|
||||||
LinkedHashTreeMap<String, String> map = new LinkedHashTreeMap<>();
|
LinkedHashTreeMap<String, String> map = new LinkedHashTreeMap<>();
|
||||||
map.put("a", "");
|
map.put("a", "");
|
||||||
assertTrue(map.containsKey("a"));
|
assertThat(map.containsKey("a")).isTrue();
|
||||||
assertEquals("", map.get("a"));
|
assertThat(map.get("a")).isEqualTo("");
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE that this does not happen every time, but given the below predictable random,
|
// NOTE that this does not happen every time, but given the below predictable random,
|
||||||
@@ -117,8 +111,8 @@ public final class LinkedHashTreeMapTest {
|
|||||||
|
|
||||||
for (int i = 0; i < keys.length; i++) {
|
for (int i = 0; i < keys.length; i++) {
|
||||||
String key = keys[i];
|
String key = keys[i];
|
||||||
assertTrue(map.containsKey(key));
|
assertThat(map.containsKey(key)).isTrue();
|
||||||
assertEquals("" + i, map.get(key));
|
assertThat(map.get(key)).isEqualTo("" + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,8 +122,8 @@ public final class LinkedHashTreeMapTest {
|
|||||||
map.put("c", "cola");
|
map.put("c", "cola");
|
||||||
map.put("b", "bbq");
|
map.put("b", "bbq");
|
||||||
map.clear();
|
map.clear();
|
||||||
assertIterationOrder(map.keySet());
|
assertThat(map.keySet()).containsExactly();
|
||||||
assertEquals(0, map.size());
|
assertThat(map).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void equalsAndHashCode() throws Exception {
|
@Test public void equalsAndHashCode() throws Exception {
|
||||||
@@ -145,8 +139,8 @@ public final class LinkedHashTreeMapTest {
|
|||||||
map2.put("D", 4);
|
map2.put("D", 4);
|
||||||
map2.put("A", 1);
|
map2.put("A", 1);
|
||||||
|
|
||||||
assertEquals(map1, map2);
|
assertThat(map2).isEqualTo(map1);
|
||||||
assertEquals(map1.hashCode(), map2.hashCode());
|
assertThat(map2.hashCode()).isEqualTo(map1.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void avlWalker() {
|
@Test public void avlWalker() {
|
||||||
@@ -166,9 +160,9 @@ public final class LinkedHashTreeMapTest {
|
|||||||
AvlIterator<String, String> iterator = new AvlIterator<>();
|
AvlIterator<String, String> iterator = new AvlIterator<>();
|
||||||
iterator.reset(root);
|
iterator.reset(root);
|
||||||
for (String value : values) {
|
for (String value : values) {
|
||||||
assertEquals(value, iterator.next().getKey());
|
assertThat(iterator.next().getKey()).isEqualTo(value);
|
||||||
}
|
}
|
||||||
assertNull(iterator.next());
|
assertThat(iterator.next()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void avlBuilder() {
|
@Test public void avlBuilder() {
|
||||||
@@ -221,7 +215,7 @@ public final class LinkedHashTreeMapTest {
|
|||||||
|
|
||||||
Node<String, String>[] newTable = LinkedHashTreeMap.doubleCapacity(oldTable);
|
Node<String, String>[] newTable = LinkedHashTreeMap.doubleCapacity(oldTable);
|
||||||
assertTree("(b d f)", newTable[0]); // Even hash codes!
|
assertTree("(b d f)", newTable[0]); // Even hash codes!
|
||||||
assertNull(newTable[1]); // Odd hash codes!
|
assertThat(newTable[1]).isNull();
|
||||||
|
|
||||||
for (Node<?, ?> node : newTable) {
|
for (Node<?, ?> node : newTable) {
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
@@ -251,7 +245,7 @@ public final class LinkedHashTreeMapTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assertTree(String expected, Node<?, ?> root) {
|
private void assertTree(String expected, Node<?, ?> root) {
|
||||||
assertEquals(expected, toString(root));
|
assertThat(toString(root)).isEqualTo(expected);
|
||||||
assertConsistent(root);
|
assertConsistent(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,17 +253,17 @@ public final class LinkedHashTreeMapTest {
|
|||||||
int leftHeight = 0;
|
int leftHeight = 0;
|
||||||
if (node.left != null) {
|
if (node.left != null) {
|
||||||
assertConsistent(node.left);
|
assertConsistent(node.left);
|
||||||
assertSame(node, node.left.parent);
|
assertThat(node.left.parent).isSameAs(node);
|
||||||
leftHeight = node.left.height;
|
leftHeight = node.left.height;
|
||||||
}
|
}
|
||||||
int rightHeight = 0;
|
int rightHeight = 0;
|
||||||
if (node.right != null) {
|
if (node.right != null) {
|
||||||
assertConsistent(node.right);
|
assertConsistent(node.right);
|
||||||
assertSame(node, node.right.parent);
|
assertThat(node.right.parent).isSameAs(node);
|
||||||
rightHeight = node.right.height;
|
rightHeight = node.right.height;
|
||||||
}
|
}
|
||||||
if (node.parent != null) {
|
if (node.parent != null) {
|
||||||
assertTrue(node.parent.left == node || node.parent.right == node);
|
assertThat(node.parent.left == node || node.parent.right == node).isTrue();
|
||||||
}
|
}
|
||||||
if (Math.max(leftHeight, rightHeight) + 1 != node.height) {
|
if (Math.max(leftHeight, rightHeight) + 1 != node.height) {
|
||||||
fail();
|
fail();
|
||||||
@@ -285,12 +279,4 @@ public final class LinkedHashTreeMapTest {
|
|||||||
return String.format("(%s %s %s)", toString(root.left), root.key, toString(root.right));
|
return String.format("(%s %s %s)", toString(root.left), root.key, toString(root.right));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> void assertIterationOrder(Iterable<T> actual, T... expected) {
|
|
||||||
ArrayList<T> actualList = new ArrayList<>();
|
|
||||||
for (T t : actual) {
|
|
||||||
actualList.add(t);
|
|
||||||
}
|
|
||||||
assertEquals(Arrays.asList(expected), actualList);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,6 @@ import org.junit.Test;
|
|||||||
import static com.squareup.moshi.TestUtil.newReader;
|
import static com.squareup.moshi.TestUtil.newReader;
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public final class MoshiTest {
|
public final class MoshiTest {
|
||||||
@@ -52,7 +51,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("null");
|
adapter.fromJson("null");
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException expected) {
|
} catch (IllegalStateException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected a boolean but was NULL at path $");
|
assertThat(expected).hasMessage("Expected a boolean but was NULL at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -95,14 +94,14 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("256");
|
adapter.fromJson("256");
|
||||||
fail();
|
fail();
|
||||||
} catch (NumberFormatException expected) {
|
} catch (NumberFormatException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected a byte but was 256 at path $");
|
assertThat(expected).hasMessage("Expected a byte but was 256 at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
adapter.fromJson("-129");
|
adapter.fromJson("-129");
|
||||||
fail();
|
fail();
|
||||||
} catch (NumberFormatException expected) {
|
} catch (NumberFormatException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected a byte but was -129 at path $");
|
assertThat(expected).hasMessage("Expected a byte but was -129 at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nulls not allowed for byte.class
|
// Nulls not allowed for byte.class
|
||||||
@@ -110,7 +109,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("null");
|
adapter.fromJson("null");
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException expected) {
|
} catch (IllegalStateException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected an int but was NULL at path $");
|
assertThat(expected).hasMessage("Expected an int but was NULL at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -191,7 +190,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("'ab'");
|
adapter.fromJson("'ab'");
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException expected) {
|
} catch (IllegalStateException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected a char but was \"ab\" at path $");
|
assertThat(expected).hasMessage("Expected a char but was \"ab\" at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nulls not allowed for char.class
|
// Nulls not allowed for char.class
|
||||||
@@ -199,7 +198,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("null");
|
adapter.fromJson("null");
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException expected) {
|
} catch (IllegalStateException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected a string but was NULL at path $");
|
assertThat(expected).hasMessage("Expected a string but was NULL at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -221,7 +220,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("'ab'");
|
adapter.fromJson("'ab'");
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException expected) {
|
} catch (IllegalStateException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected a char but was \"ab\" at path $");
|
assertThat(expected).hasMessage("Expected a char but was \"ab\" at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow nulls for Character.class
|
// Allow nulls for Character.class
|
||||||
@@ -255,7 +254,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("null");
|
adapter.fromJson("null");
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException expected) {
|
} catch (IllegalStateException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected a double but was NULL at path $");
|
assertThat(expected).hasMessage("Expected a double but was NULL at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -272,7 +271,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson(reader);
|
adapter.fromJson(reader);
|
||||||
fail();
|
fail();
|
||||||
} catch (NumberFormatException expected) {
|
} catch (NumberFormatException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("JSON forbids NaN and infinities: Infinity at path $[0]");
|
assertThat(expected).hasMessage("JSON forbids NaN and infinities: Infinity at path $[0]");
|
||||||
}
|
}
|
||||||
|
|
||||||
reader = newReader("[-1E309]");
|
reader = newReader("[-1E309]");
|
||||||
@@ -281,7 +280,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson(reader);
|
adapter.fromJson(reader);
|
||||||
fail();
|
fail();
|
||||||
} catch (NumberFormatException expected) {
|
} catch (NumberFormatException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("JSON forbids NaN and infinities: -Infinity at path $[0]");
|
assertThat(expected).hasMessage("JSON forbids NaN and infinities: -Infinity at path $[0]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +322,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("null");
|
adapter.fromJson("null");
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException expected) {
|
} catch (IllegalStateException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected a double but was NULL at path $");
|
assertThat(expected).hasMessage("Expected a double but was NULL at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -340,7 +339,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson(reader);
|
adapter.fromJson(reader);
|
||||||
fail();
|
fail();
|
||||||
} catch (NumberFormatException expected) {
|
} catch (NumberFormatException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("JSON forbids NaN and infinities: Infinity at path $[1]");
|
assertThat(expected).hasMessage("JSON forbids NaN and infinities: Infinity at path $[1]");
|
||||||
}
|
}
|
||||||
|
|
||||||
reader = newReader("[-1E39]");
|
reader = newReader("[-1E39]");
|
||||||
@@ -349,7 +348,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson(reader);
|
adapter.fromJson(reader);
|
||||||
fail();
|
fail();
|
||||||
} catch (NumberFormatException expected) {
|
} catch (NumberFormatException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("JSON forbids NaN and infinities: -Infinity at path $[1]");
|
assertThat(expected).hasMessage("JSON forbids NaN and infinities: -Infinity at path $[1]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,14 +380,14 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("2147483648");
|
adapter.fromJson("2147483648");
|
||||||
fail();
|
fail();
|
||||||
} catch (NumberFormatException expected) {
|
} catch (NumberFormatException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected an int but was 2147483648 at path $");
|
assertThat(expected).hasMessage("Expected an int but was 2147483648 at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
adapter.fromJson("-2147483649");
|
adapter.fromJson("-2147483649");
|
||||||
fail();
|
fail();
|
||||||
} catch (NumberFormatException expected) {
|
} catch (NumberFormatException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected an int but was -2147483649 at path $");
|
assertThat(expected).hasMessage("Expected an int but was -2147483649 at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nulls not allowed for int.class
|
// Nulls not allowed for int.class
|
||||||
@@ -396,7 +395,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("null");
|
adapter.fromJson("null");
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException expected) {
|
} catch (IllegalStateException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected an int but was NULL at path $");
|
assertThat(expected).hasMessage("Expected an int but was NULL at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -434,14 +433,14 @@ public final class MoshiTest {
|
|||||||
// adapter.fromJson("9223372036854775808");
|
// adapter.fromJson("9223372036854775808");
|
||||||
// fail();
|
// fail();
|
||||||
//} catch (NumberFormatException expected) {
|
//} catch (NumberFormatException expected) {
|
||||||
// assertThat(expected.getMessage()).isEqualTo("Expected a long but was 9223372036854775808 at path $");
|
// assertThat(expected).hasMessage("Expected a long but was 9223372036854775808 at path $");
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//try {
|
//try {
|
||||||
// adapter.fromJson("-9223372036854775809");
|
// adapter.fromJson("-9223372036854775809");
|
||||||
// fail();
|
// fail();
|
||||||
//} catch (NumberFormatException expected) {
|
//} catch (NumberFormatException expected) {
|
||||||
// assertThat(expected.getMessage()).isEqualTo("Expected a long but was -9223372036854775809 at path $");
|
// assertThat(expected).hasMessage("Expected a long but was -9223372036854775809 at path $");
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// Nulls not allowed for long.class
|
// Nulls not allowed for long.class
|
||||||
@@ -449,7 +448,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("null");
|
adapter.fromJson("null");
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException expected) {
|
} catch (IllegalStateException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected a long but was NULL at path $");
|
assertThat(expected).hasMessage("Expected a long but was NULL at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -485,14 +484,14 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("32768");
|
adapter.fromJson("32768");
|
||||||
fail();
|
fail();
|
||||||
} catch (NumberFormatException expected) {
|
} catch (NumberFormatException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected a short but was 32768 at path $");
|
assertThat(expected).hasMessage("Expected a short but was 32768 at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
adapter.fromJson("-32769");
|
adapter.fromJson("-32769");
|
||||||
fail();
|
fail();
|
||||||
} catch (NumberFormatException expected) {
|
} catch (NumberFormatException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected a short but was -32769 at path $");
|
assertThat(expected).hasMessage("Expected a short but was -32769 at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nulls not allowed for short.class
|
// Nulls not allowed for short.class
|
||||||
@@ -500,7 +499,7 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("null");
|
adapter.fromJson("null");
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException expected) {
|
} catch (IllegalStateException expected) {
|
||||||
assertThat(expected.getMessage()).isEqualTo("Expected an int but was NULL at path $");
|
assertThat(expected).hasMessage("Expected an int but was NULL at path $");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -645,8 +644,8 @@ public final class MoshiTest {
|
|||||||
Util.jsonAnnotations(uppercaseStringsField));
|
Util.jsonAnnotations(uppercaseStringsField));
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (IllegalArgumentException expected) {
|
||||||
assertEquals("no JsonAdapter for java.util.List<java.lang.String> annotated "
|
assertThat(expected).hasMessage( "no JsonAdapter for java.util.List<java.lang.String> "
|
||||||
+ "[@com.squareup.moshi.MoshiTest$Uppercase()]", expected.getMessage());
|
+ "annotated [@com.squareup.moshi.MoshiTest$Uppercase()]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,8 +677,8 @@ public final class MoshiTest {
|
|||||||
adapter.fromJson("\"SPOCK\"");
|
adapter.fromJson("\"SPOCK\"");
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException expected) {
|
} catch (IllegalStateException expected) {
|
||||||
assertThat(expected.getMessage())
|
assertThat(expected).hasMessage(
|
||||||
.isEqualTo("Expected one of [ROCK, PAPER, SCISSORS] but was SPOCK at path $");
|
"Expected one of [ROCK, PAPER, SCISSORS] but was SPOCK at path $");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,7 +24,6 @@ import java.util.Properties;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public final class TypesTest {
|
public final class TypesTest {
|
||||||
@@ -53,7 +52,7 @@ public final class TypesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test public void getFirstTypeArgument() throws Exception {
|
@Test public void getFirstTypeArgument() throws Exception {
|
||||||
assertNull(getFirstTypeArgument(A.class));
|
assertThat(getFirstTypeArgument(A.class)).isNull();
|
||||||
|
|
||||||
Type type = Types.newParameterizedType(A.class, B.class, C.class);
|
Type type = Types.newParameterizedType(A.class, B.class, C.class);
|
||||||
assertThat(getFirstTypeArgument(type)).isEqualTo(B.class);
|
assertThat(getFirstTypeArgument(type)).isEqualTo(B.class);
|
||||||
|
Reference in New Issue
Block a user