1717
1818import androidx .annotation .NonNull ;
1919
20+ import com .amplifyframework .AmplifyException ;
2021import com .amplifyframework .core .Consumer ;
2122import com .amplifyframework .core .model .Model ;
23+ import com .amplifyframework .core .model .ModelSchema ;
2224import com .amplifyframework .datastore .DataStoreConfiguration .ConfigKey ;
2325import com .amplifyframework .datastore .DataStoreConflictHandler .AlwaysApplyRemoteHandler ;
2426import com .amplifyframework .testmodels .commentsblog .BlogOwner ;
27+ import com .amplifyframework .testmodels .commentsblog .Post ;
2528import com .amplifyframework .testutils .random .RandomString ;
2629
2730import org .json .JSONException ;
3134import org .robolectric .RobolectricTestRunner ;
3235
3336import java .util .Collections ;
37+ import java .util .HashMap ;
38+ import java .util .Map ;
3439import java .util .concurrent .TimeUnit ;
3540
3641import static org .junit .Assert .assertEquals ;
@@ -91,23 +96,27 @@ public void testDefaultOverriddenFromConfiguration() throws JSONException, DataS
9196 * When building a configuration from both a config file and a configuration object,
9297 * default values should be overridden, and the provided ones shall be used, instead.
9398 * @throws JSONException While arranging config file JSON
94- * @throws DataStoreException While building DataStoreConfiguration instances via build()
99+ * @throws AmplifyException While building DataStoreConfiguration instances via build(), or when deriving a
100+ * {@link ModelSchema} from a {@link Model} class.
95101 */
96102 @ Test
97- public void testDefaultOverriddenFromConfigurationAndObject () throws JSONException , DataStoreException {
103+ public void testDefaultOverriddenFromConfigurationAndObject ()
104+ throws JSONException , AmplifyException {
98105 long expectedSyncIntervalMinutes = 6L ;
99106 Long expectedSyncIntervalMs = TimeUnit .MINUTES .toMillis (expectedSyncIntervalMinutes );
100107 Integer expectedSyncMaxRecords = 3 ;
101108 DummyConflictHandler dummyConflictHandler = new DummyConflictHandler ();
102109 DataStoreErrorHandler errorHandler = DefaultDataStoreErrorHandler .instance ();
103110
104- DataStoreSyncExpression syncExpression = () -> BlogOwner .ID .beginsWith (RandomString .string ());
111+ DataStoreSyncExpression ownerSyncExpression = () -> BlogOwner .ID .beginsWith (RandomString .string ());
112+ DataStoreSyncExpression postSyncExpression = () -> Post .ID .beginsWith (RandomString .string ());
105113 DataStoreConfiguration configObject = DataStoreConfiguration
106114 .builder ()
107115 .syncMaxRecords (expectedSyncMaxRecords )
108116 .conflictHandler (dummyConflictHandler )
109117 .errorHandler (errorHandler )
110- .syncExpression (BlogOwner .class , syncExpression )
118+ .syncExpression (BlogOwner .class , ownerSyncExpression )
119+ .syncExpression ("Post" , postSyncExpression )
111120 .build ();
112121
113122 JSONObject jsonConfigFromFile = new JSONObject ()
@@ -123,8 +132,11 @@ public void testDefaultOverriddenFromConfigurationAndObject() throws JSONExcepti
123132
124133 assertEquals (dummyConflictHandler , dataStoreConfiguration .getConflictHandler ());
125134 assertEquals (errorHandler , dataStoreConfiguration .getErrorHandler ());
126- assertEquals (Collections .singletonMap (BlogOwner .class .getSimpleName (), syncExpression ),
127- dataStoreConfiguration .getSyncExpressions ());
135+
136+ Map <String , DataStoreSyncExpression > expectedSyncExpressions = new HashMap <>();
137+ expectedSyncExpressions .put (BlogOwner .class .getSimpleName (), ownerSyncExpression );
138+ expectedSyncExpressions .put (Post .class .getSimpleName (), postSyncExpression );
139+ assertEquals (expectedSyncExpressions , dataStoreConfiguration .getSyncExpressions ());
128140 }
129141
130142 /**
0 commit comments