Skip to content

Commit

Permalink
Limit the characters to 100 per line in the utility and data modules (#…
Browse files Browse the repository at this point in the history
…1315)

* Fix line length errors

* Fix lint errors in data module

* Update circleci ktlint method

* Change import ordering to follow intelliJ optimized imports

* Only lint src files of modules

* New line at EOF in editorconfig

* Fix lint issues in merged PRs

* Fix parser error

* Reformat DataProvidersTest

* Review changes

* Add space after end comment
  • Loading branch information
vinitamurthi authored Jun 16, 2020
1 parent fa9e9bf commit 2ca2397
Show file tree
Hide file tree
Showing 23 changed files with 1,196 additions and 575 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
chmod +x /home/circleci/oppia-android/buf
- run:
name: Kotlin tests - Data, Utility
command: ./ktlint utility/**/*.kt data/**/*.kt && echo "Lint completed successfully"
command: ./ktlint --android utility/src/**/*.kt data/src/**/*.kt && echo "Lint completed successfully"
- run:
name: Protobuf lint check
command: ./buf check lint --input=model/src/main/proto --input-config buf.yaml && echo "Protobuf lint check completed successfully"
Expand Down
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[*.{kt,kts}]
# possible values: number (e.g. 2), "unset" (makes ktlint ignore indentation completely)
indent_size=2
kotlin_imports_layout=idea
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ import retrofit2.http.Path
interface ExplorationService {

@GET("explorehandler/init/{exploration_id}")
fun getExplorationById(@Path("exploration_id") explorationId: String): Call<GaeExplorationContainer>
fun getExplorationById(
@Path("exploration_id") explorationId: String
): Call<GaeExplorationContainer>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ import retrofit2.http.Path
interface SubtopicService {

@GET("subtopic_data_handler/{topic_name}/{subtopic_id}")
fun getSubtopic(@Path("topic_name") topicName: String, @Path("subtopic_id") subtopicId: String): Call<GaeSubtopic>
fun getSubtopic(
@Path("topic_name") topicName: String,
@Path("subtopic_id") subtopicId: String
): Call<GaeSubtopic>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,25 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class GaeExplorationContainer(

@Json(name = "record_playthrough_probability") val recordPlaythroughProbability: Float?,
@Json(name = "exploration_id") val explorationId: String?,
@Json(name = "state_classifier_mapping") val stateClassifierMapping: Map<String, GaeStateClassifier>?,
@Json(name = "user_email") val userEmail: String?,
@Json(name = "version") val version: Int?,
@Json(name = "correctness_feedback_enabled") val isCorrectnessFeedbackEnabled: Boolean?,
@Json(name = "username") val username: String?,
@Json(name = "is_logged_in") val isLoggedIn: Boolean?,
@Json(name = "exploration") val exploration: GaeExploration?,
@Json(name = "session_id") val sessionId: String?
@Json(name = "record_playthrough_probability")
val recordPlaythroughProbability: Float?,
@Json(name = "exploration_id")
val explorationId: String?,
@Json(name = "state_classifier_mapping")
val stateClassifierMapping: Map<String, GaeStateClassifier>?,
@Json(name = "user_email")
val userEmail: String?,
@Json(name = "version")
val version: Int?,
@Json(name = "correctness_feedback_enabled")
val isCorrectnessFeedbackEnabled: Boolean?,
@Json(name = "username")
val username: String?,
@Json(name = "is_logged_in")
val isLoggedIn: Boolean?,
@Json(name = "exploration")
val exploration: GaeExploration?,
@Json(name = "session_id")
val sessionId: String?

)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class GaeWrittenTranslations(

@Json(name = "translations_mapping") val translationsMapping: Map<String, Map<String, GaeWrittenTranslation>>?
@Json(name = "translations_mapping")
val translationsMapping: Map<String, Map<String, GaeWrittenTranslation>>?

)
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ class PersistentCacheStore<T : MessageLite> private constructor(
private val failureLock = ReentrantLock()

private val cacheFile = File(directory, cacheFileName)
@GuardedBy("failureLock") private var deferredLoadCacheFailure: Throwable? = null
private val cache = cacheFactory.create(CachePayload(state = CacheState.UNLOADED, value = initialValue))
@GuardedBy("failureLock")
private var deferredLoadCacheFailure: Throwable? = null
private val cache =
cacheFactory.create(CachePayload(state = CacheState.UNLOADED, value = initialValue))

init {
cache.observeChanges {
Expand Down Expand Up @@ -146,10 +148,16 @@ class PersistentCacheStore<T : MessageLite> private constructor(
}

/** See [storeDataAsync]. Stores data and allows for a custom deferred result. */
fun <V> storeDataWithCustomChannelAsync(updateInMemoryCache: Boolean = true, update: (T) -> Pair<T, V>): Deferred<V> {
fun <V> storeDataWithCustomChannelAsync(
updateInMemoryCache: Boolean = true,
update: (T) -> Pair<T, V>
): Deferred<V> {
return cache.updateWithCustomChannelIfPresentAsync { cachedPayload ->
val (updatedPayload, customResult) = storeFileCacheWithCustomChannel(cachedPayload, update)
if (updateInMemoryCache) Pair(updatedPayload, customResult) else Pair(cachedPayload, customResult)
if (updateInMemoryCache) Pair(updatedPayload, customResult) else Pair(
cachedPayload,
customResult
)
}
}

Expand Down Expand Up @@ -222,10 +230,16 @@ class PersistentCacheStore<T : MessageLite> private constructor(
}

/** See [storeFileCache]. Returns payload and custom result. */
private fun <V> storeFileCacheWithCustomChannel(currentPayload: CachePayload<T>, update: (T) -> Pair<T, V>): Pair<CachePayload<T>, V> {
private fun <V> storeFileCacheWithCustomChannel(
currentPayload: CachePayload<T>,
update: (T) -> Pair<T, V>
): Pair<CachePayload<T>, V> {
val (updatedCacheValue, customResult) = update(currentPayload.value)
FileOutputStream(cacheFile).use { updatedCacheValue.writeTo(it) }
return Pair(CachePayload(state = CacheState.IN_MEMORY_AND_ON_DISK, value = updatedCacheValue), customResult)
return Pair(
CachePayload(state = CacheState.IN_MEMORY_AND_ON_DISK, value = updatedCacheValue),
customResult
)
}

private data class PersistentCacheStoreId(private val id: String)
Expand Down Expand Up @@ -268,16 +282,33 @@ class PersistentCacheStore<T : MessageLite> private constructor(
* Use this method when data is shared by all profiles.
*/
fun <T : MessageLite> create(cacheName: String, initialValue: T): PersistentCacheStore<T> {
return PersistentCacheStore(context, cacheFactory, asyncDataSubscriptionManager, cacheName, initialValue)
return PersistentCacheStore(
context,
cacheFactory,
asyncDataSubscriptionManager,
cacheName,
initialValue
)
}

/**
* Returns a new [PersistentCacheStore] with the specified cache name and initial value under the directory specified by profileId.
* Use this method when data is unique to each profile.
*/
fun <T : MessageLite> createPerProfile(cacheName: String, initialValue: T, profileId: ProfileId): PersistentCacheStore<T> {
fun <T : MessageLite> createPerProfile(
cacheName: String,
initialValue: T,
profileId: ProfileId
): PersistentCacheStore<T> {
val profileDirectory = directoryManagementUtil.getOrCreateDir(profileId.internalId.toString())
return PersistentCacheStore(context, cacheFactory, asyncDataSubscriptionManager, cacheName, initialValue, profileDirectory)
return PersistentCacheStore(
context,
cacheFactory,
asyncDataSubscriptionManager,
cacheName,
initialValue,
profileDirectory
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import javax.inject.Singleton
@RunWith(AndroidJUnit4::class)
class NetworkInterceptorTest {

@Inject lateinit var networkInterceptor: NetworkInterceptor
@Inject
lateinit var networkInterceptor: NetworkInterceptor

@Before
fun setUp() {
Expand All @@ -38,17 +39,33 @@ class NetworkInterceptorTest {
@Test
fun testNetworkInterceptor_withXssiPrefix_removesXssiPrefix() {
val rawJson: String =
networkInterceptor.removeXSSIPrefix(ApiUtils.getFakeJson("dummy_response_with_xssi_prefix.json")).trim()
networkInterceptor.removeXSSIPrefix(
ApiUtils.getFakeJson(
"dummy_response_with_xssi_prefix.json"
)
).trim()

assertThat(removeSpaces(rawJson)).isEqualTo(ApiUtils.getFakeJson("dummy_response_without_xssi_prefix.json"))
assertThat(removeSpaces(rawJson)).isEqualTo(
ApiUtils.getFakeJson(
"dummy_response_without_xssi_prefix.json"
)
)
}

@Test
fun testNetworkInterceptor_withoutXssiPrefix_removesXssiPrefix() {
val rawJson: String =
networkInterceptor.removeXSSIPrefix(ApiUtils.getFakeJson("dummy_response_without_xssi_prefix.json"))
networkInterceptor.removeXSSIPrefix(
ApiUtils.getFakeJson(
"dummy_response_without_xssi_prefix.json"
)
)

assertThat(rawJson).isEqualTo(ApiUtils.getFakeJson("dummy_response_without_xssi_prefix.json"))
assertThat(rawJson).isEqualTo(
ApiUtils.getFakeJson(
"dummy_response_without_xssi_prefix.json"
)
)
}

private fun setUpTestApplicationComponent() {
Expand All @@ -58,7 +75,8 @@ class NetworkInterceptorTest {
.inject(this)
}

@Qualifier annotation class OppiaRetrofit
@Qualifier
annotation class OppiaRetrofit

// TODO(#89): Move this to a common test application component.
@Module
Expand Down
Loading

0 comments on commit 2ca2397

Please sign in to comment.