mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 07:59:21 +08:00
Standardize (almost) all tests on Truth (#1242)
* Replace assertj calls with Truth where possible * Update test dependencies * adapters * reflect * codegen * moshi * Add missing inOrder() * Spotless
This commit is contained in:
@@ -25,5 +25,5 @@ dependencies {
|
||||
|
||||
testCompileOnly(Dependencies.jsr305)
|
||||
testImplementation(Dependencies.Testing.junit)
|
||||
testImplementation(Dependencies.Testing.assertj)
|
||||
testImplementation(Dependencies.Testing.truth)
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.squareup.moshi.adapters;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.squareup.moshi.Json;
|
||||
@@ -48,7 +48,9 @@ public final class EnumJsonAdapterTest {
|
||||
adapter.fromJson(reader);
|
||||
fail();
|
||||
} catch (JsonDataException expected) {
|
||||
assertThat(expected).hasMessage("Expected one of [ROCK, PAPER, scr] but was SPOCK at path $");
|
||||
assertThat(expected)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Expected one of [ROCK, PAPER, scr] but was SPOCK at path $");
|
||||
}
|
||||
assertThat(reader.peek()).isEqualTo(JsonReader.Token.END_DOCUMENT);
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.squareup.moshi.adapters;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.squareup.moshi.JsonAdapter;
|
||||
@@ -84,7 +84,8 @@ public final class PolymorphicJsonAdapterFactoryTest {
|
||||
fail();
|
||||
} catch (JsonDataException expected) {
|
||||
assertThat(expected)
|
||||
.hasMessage(
|
||||
.hasMessageThat()
|
||||
.isEqualTo(
|
||||
"Expected one of [success, error] for key 'type' but found"
|
||||
+ " 'data'. Register a subtype for this label.");
|
||||
}
|
||||
@@ -105,7 +106,7 @@ public final class PolymorphicJsonAdapterFactoryTest {
|
||||
JsonAdapter<Message> adapter = moshi.adapter(Message.class);
|
||||
|
||||
Message message = adapter.fromJson("{\"type\":\"data\",\"value\":\"Okay!\"}");
|
||||
assertThat(message).isSameAs(fallbackError);
|
||||
assertThat(message).isSameInstanceAs(fallbackError);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,7 +177,8 @@ public final class PolymorphicJsonAdapterFactoryTest {
|
||||
adapter.toJson(new EmptyMessage());
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertThat(expected)
|
||||
.hasMessage(
|
||||
.hasMessageThat()
|
||||
.isEqualTo(
|
||||
"Expected one of [class"
|
||||
+ " com.squareup.moshi.adapters.PolymorphicJsonAdapterFactoryTest$Success, class"
|
||||
+ " com.squareup.moshi.adapters.PolymorphicJsonAdapterFactoryTest$Error] but found"
|
||||
@@ -203,7 +205,8 @@ public final class PolymorphicJsonAdapterFactoryTest {
|
||||
adapter.toJson(new EmptyMessage());
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertThat(expected)
|
||||
.hasMessage(
|
||||
.hasMessageThat()
|
||||
.isEqualTo(
|
||||
"Expected one of [class"
|
||||
+ " com.squareup.moshi.adapters.PolymorphicJsonAdapterFactoryTest$Success, class"
|
||||
+ " com.squareup.moshi.adapters.PolymorphicJsonAdapterFactoryTest$Error] but found"
|
||||
@@ -256,7 +259,9 @@ public final class PolymorphicJsonAdapterFactoryTest {
|
||||
adapter.fromJson("{\"type\":{},\"value\":\"Okay!\"}");
|
||||
fail();
|
||||
} catch (JsonDataException expected) {
|
||||
assertThat(expected).hasMessage("Expected a string but was BEGIN_OBJECT at path $.type");
|
||||
assertThat(expected)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Expected a string but was BEGIN_OBJECT at path $.type");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,7 +281,9 @@ public final class PolymorphicJsonAdapterFactoryTest {
|
||||
adapter.fromJson(reader);
|
||||
fail();
|
||||
} catch (JsonDataException expected) {
|
||||
assertThat(expected).hasMessage("Expected BEGIN_OBJECT but was STRING at path $");
|
||||
assertThat(expected)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Expected BEGIN_OBJECT but was STRING at path $");
|
||||
}
|
||||
assertThat(reader.nextString()).isEqualTo("Failure");
|
||||
assertThat(reader.peek()).isEqualTo(JsonReader.Token.END_DOCUMENT);
|
||||
@@ -313,7 +320,7 @@ public final class PolymorphicJsonAdapterFactoryTest {
|
||||
factory.withSubtype(Error.class, "data");
|
||||
fail();
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertThat(expected).hasMessage("Labels must be unique.");
|
||||
assertThat(expected).hasMessageThat().isEqualTo("Labels must be unique.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.squareup.moshi.adapters;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.squareup.moshi.JsonAdapter;
|
||||
import java.util.Calendar;
|
||||
|
Reference in New Issue
Block a user