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:
Zac Sweers
2020-09-26 20:38:39 -04:00
committed by GitHub
parent acb2836d39
commit f192473419
36 changed files with 448 additions and 300 deletions

View File

@@ -25,5 +25,5 @@ dependencies {
testCompileOnly(Dependencies.jsr305)
testImplementation(Dependencies.Testing.junit)
testImplementation(Dependencies.Testing.assertj)
testImplementation(Dependencies.Testing.truth)
}

View File

@@ -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);
}

View File

@@ -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.");
}
}

View File

@@ -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;