|
20 | 20 |
|
21 | 21 | import com.amplifyframework.AmplifyException; |
22 | 22 | import com.amplifyframework.core.category.CategoryConfiguration; |
| 23 | +import com.amplifyframework.core.category.CategoryInitializationResult; |
| 24 | +import com.amplifyframework.core.configuration.AmplifyOutputsData; |
23 | 25 | import com.amplifyframework.testutils.random.RandomString; |
24 | 26 |
|
25 | 27 | import org.json.JSONException; |
26 | 28 | import org.json.JSONObject; |
27 | 29 | import org.junit.Before; |
28 | 30 | import org.junit.Test; |
29 | 31 | import org.junit.runner.RunWith; |
| 32 | +import org.mockito.Mockito; |
30 | 33 | import org.robolectric.RobolectricTestRunner; |
31 | 34 |
|
32 | 35 | import java.util.List; |
@@ -135,6 +138,28 @@ public void configuredPluginUsedWhenProvided() throws AmplifyException { |
135 | 138 | firstLog.assertEquals(LogLevel.WARN, message, issue); |
136 | 139 | } |
137 | 140 |
|
| 141 | + /** |
| 142 | + * Category should initialize as normal when using a Gen2 configuration. |
| 143 | + * @throws AmplifyException Not expected; possible from addPlugin() call |
| 144 | + */ |
| 145 | + @Test |
| 146 | + public void initializationSucceedsForGen2() throws AmplifyException { |
| 147 | + FakeLogger userLogger = FakeLogger.instance(RandomString.string(), LogLevel.VERBOSE); |
| 148 | + FakeLoggingPlugin<Void> userPlugin = FakeLoggingPlugin.instance(userLogger); |
| 149 | + realLoggingCategory.addPlugin(userPlugin); |
| 150 | + |
| 151 | + AmplifyOutputsData data = Mockito.mock(AmplifyOutputsData.class); |
| 152 | + realLoggingCategory.configure(data, getApplicationContext()); |
| 153 | + |
| 154 | + // Ensure initialization succeeds |
| 155 | + CategoryInitializationResult result = realLoggingCategory.initialize(getApplicationContext()); |
| 156 | + assertTrue(result.isSuccess()); |
| 157 | + |
| 158 | + // Ensure we can fetch the plugin |
| 159 | + LoggingPlugin<?> plugin = realLoggingCategory.getPlugin(userPlugin.getPluginKey()); |
| 160 | + assertEquals(userPlugin, plugin); |
| 161 | + } |
| 162 | + |
138 | 163 | private static LoggingCategoryConfiguration loggingConfiguration() { |
139 | 164 | LoggingCategoryConfiguration configuration = new LoggingCategoryConfiguration(); |
140 | 165 | try { |
|
0 commit comments