@Test public void testRetrieveBasicCoder() throws CoderNotFoundException { Class fieldClass = String.class; SaveState mockedSaveState = mock(SaveState.class); when(mockedSaveState.value()).thenAnswer(new Answer<Class<? extends StateCoder>>() { @Override public Class<? extends StateCoder> answer(InvocationOnMock invocationOnMock) throws Throwable { return StateCoder.class; } }); StateCoder retrieverCoder = mRetriever.getCoder(mockedSaveState, fieldClass); assertNotNull(retrieverCoder); StateCoder basicCoder = StateCoderUtils.getBasicCoderForClass(fieldClass); assertEquals(retrieverCoder.getClass(), basicCoder.getClass()); }
@NonNull @Override public StateCoder getCoder(@NonNull SaveState saveState, @NonNull Class<?> annotatedFieldClass) throws CoderNotFoundException { StateCoder stateCoder; final Class<? extends StateCoder> stateSDClass = saveState.value(); if (GsonCoder.class.isAssignableFrom(stateSDClass)) { try { Constructor<? extends StateCoder> constructor; constructor = stateSDClass.getConstructor(Gson.class); boolean accessible = constructor.isAccessible(); if (!accessible) { constructor.setAccessible(true); } stateCoder = constructor.newInstance(mGson); if (!accessible) { constructor.setAccessible(false); } } catch (Exception e) { throw new RuntimeException("You must provide an instance of " + GsonCoder.class.getName()); } } else { stateCoder = super.getCoder(saveState, annotatedFieldClass); } return stateCoder; }
DefaultGsonCoderRetriever extends DefaultCoderRetriever { @NonNull @Override public StateCoder getCoder(@NonNull SaveState saveState, @NonNull Class<?> annotatedFieldClass) throws CoderNotFoundException { StateCoder stateCoder; final Class<? extends StateCoder> stateSDClass = saveState.value(); if (GsonCoder.class.isAssignableFrom(stateSDClass)) { try { Constructor<? extends StateCoder> constructor; constructor = stateSDClass.getConstructor(Gson.class); boolean accessible = constructor.isAccessible(); if (!accessible) { constructor.setAccessible(true); } stateCoder = constructor.newInstance(mGson); if (!accessible) { constructor.setAccessible(false); } } catch (Exception e) { throw new RuntimeException("You must provide an instance of " + GsonCoder.class.getName()); } } else { stateCoder = super.getCoder(saveState, annotatedFieldClass); } return stateCoder; } }
DefaultGsonCoderRetriever extends DefaultCoderRetriever { @NonNull @Override public StateCoder getCoder(@NonNull SaveState saveState, @NonNull Class<?> annotatedFieldClass) throws CoderNotFoundException { StateCoder stateCoder; final Class<? extends StateCoder> stateSDClass = saveState.value(); if (GsonCoder.class.isAssignableFrom(stateSDClass)) { try { Constructor<? extends StateCoder> constructor; constructor = stateSDClass.getConstructor(Gson.class); boolean accessible = constructor.isAccessible(); if (!accessible) { constructor.setAccessible(true); } stateCoder = constructor.newInstance(mGson); if (!accessible) { constructor.setAccessible(false); } } catch (Exception e) { throw new RuntimeException("You must provide an instance of " + GsonCoder.class.getName()); } } else { stateCoder = super.getCoder(saveState, annotatedFieldClass); } return stateCoder; } DefaultGsonCoderRetriever();  DefaultGsonCoderRetriever(@NonNull Gson gson); }
DefaultGsonCoderRetriever extends DefaultCoderRetriever { @NonNull @Override public StateCoder getCoder(@NonNull SaveState saveState, @NonNull Class<?> annotatedFieldClass) throws CoderNotFoundException { StateCoder stateCoder; final Class<? extends StateCoder> stateSDClass = saveState.value(); if (GsonCoder.class.isAssignableFrom(stateSDClass)) { try { Constructor<? extends StateCoder> constructor; constructor = stateSDClass.getConstructor(Gson.class); boolean accessible = constructor.isAccessible(); if (!accessible) { constructor.setAccessible(true); } stateCoder = constructor.newInstance(mGson); if (!accessible) { constructor.setAccessible(false); } } catch (Exception e) { throw new RuntimeException("You must provide an instance of " + GsonCoder.class.getName()); } } else { stateCoder = super.getCoder(saveState, annotatedFieldClass); } return stateCoder; } DefaultGsonCoderRetriever();  DefaultGsonCoderRetriever(@NonNull Gson gson); @NonNull @Override StateCoder getCoder(@NonNull SaveState saveState, @NonNull Class<?> annotatedFieldClass); }
DefaultGsonCoderRetriever extends DefaultCoderRetriever { @NonNull @Override public StateCoder getCoder(@NonNull SaveState saveState, @NonNull Class<?> annotatedFieldClass) throws CoderNotFoundException { StateCoder stateCoder; final Class<? extends StateCoder> stateSDClass = saveState.value(); if (GsonCoder.class.isAssignableFrom(stateSDClass)) { try { Constructor<? extends StateCoder> constructor; constructor = stateSDClass.getConstructor(Gson.class); boolean accessible = constructor.isAccessible(); if (!accessible) { constructor.setAccessible(true); } stateCoder = constructor.newInstance(mGson); if (!accessible) { constructor.setAccessible(false); } } catch (Exception e) { throw new RuntimeException("You must provide an instance of " + GsonCoder.class.getName()); } } else { stateCoder = super.getCoder(saveState, annotatedFieldClass); } return stateCoder; } DefaultGsonCoderRetriever();  DefaultGsonCoderRetriever(@NonNull Gson gson); @NonNull @Override StateCoder getCoder(@NonNull SaveState saveState, @NonNull Class<?> annotatedFieldClass);  }