クラス GsonTester<T>

型パラメーター:
T - テスト中の型

public class GsonTester<T> extends AbstractJsonMarshalTester<T>
Gson が支援する AssertJ ベースの JSON テスター。通常、initFields(Object, Gson) を介してインスタンス化されます。例:
 public class ExampleObjectJsonTests {

     private GsonTester<ExampleObject> json;

     @Before
     public void setup() {
         Gson gson = new GsonBuilder().create();
         GsonTester.initFields(this, gson);
     }

     @Test
     public void testWriteJson() throws IOException {
         ExampleObject object = //...
         assertThat(json.write(object)).isEqualToJson("expected.json");
     }

 }
 
詳細については、AbstractJsonMarshalTester を参照してください。
導入:
1.4.0
作成者:
Phillip Webb
  • コンストラクターの詳細

    • GsonTester

      protected GsonTester(com.google.gson.Gson gson)
      初期化されていない新しい GsonTester インスタンスを作成します。
      パラメーター:
      gson - Gson インスタンス
    • GsonTester

      public GsonTester(ClassSE<?> resourceLoadClass, ResolvableType type, com.google.gson.Gson gson)
      新しい GsonTester インスタンスを作成します。
      パラメーター:
      resourceLoadClass - リソースのロードに使用されるソースクラス
      type - テスト中の型
      gson - Gson インスタンス
      関連事項:
  • メソッドの詳細

    • writeObject

      protected StringSE writeObject(T value, ResolvableType type) throws IOExceptionSE
      クラスからコピーされた説明: AbstractJsonMarshalTester
      指定されたオブジェクトを JSON 文字列に書き込みます。
      次で指定:
      クラス AbstractJsonMarshalTester<T>writeObject 
      パラメーター:
      value - ソース値 (非 null)
      type - 結果の型 (非 null)
      戻り値:
      JSON 文字列
      例外:
      IOExceptionSE - 書き込みエラー時
    • readObject

      protected T readObject(ReaderSE reader, ResolvableType type) throws IOExceptionSE
      クラスからコピーされた説明: AbstractJsonMarshalTester
      指定したリーダーから読み取り、指定した型のオブジェクトを作成します。
      次で指定:
      クラス AbstractJsonMarshalTester<T>readObject 
      パラメーター:
      reader - ソースリーダー (非 null)
      type - 結果の型 (非 null)
      戻り値:
      結果のオブジェクト
      例外:
      IOExceptionSE - 読み取りエラー時
    • initFields

      public static void initFields(ObjectSE testInstance, com.google.gson.Gson gson)
      GsonTester フィールドを初期化するユーティリティメソッド。使用例については、class-level documentation を参照してください。
      パラメーター:
      testInstance - テストインスタンス
      gson - Gson インスタンス
    • initFields

      public static void initFields(ObjectSE testInstance, ObjectFactory<com.google.gson.Gson> gson)
      GsonTester フィールドを初期化するユーティリティメソッド。使用例については、class-level documentation を参照してください。
      パラメーター:
      testInstance - テストインスタンス
      gson - Gson インスタンスを作成するためのオブジェクトファクトリ