Skip to content

Commit

Permalink
chore: format kotlin file with ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
Bambooin committed Feb 21, 2024
1 parent 3cc1b3b commit 45178b3
Show file tree
Hide file tree
Showing 371 changed files with 9,000 additions and 7,833 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import java.util.concurrent.TimeUnit
@Suppress("StringLiteralDuplication")
@androidx.test.filters.Suppress
class FtpServiceEspressoTest {

@get:Rule
var serviceTestRule = ServiceTestRule()

Expand All @@ -88,10 +87,11 @@ class FtpServiceEspressoTest {
.remove(FtpService.KEY_PREFERENCE_USERNAME)
.remove(FtpService.KEY_PREFERENCE_PASSWORD)
.commit()
service = create(
Intent(FtpService.ACTION_START_FTPSERVER)
.putExtra(FtpService.TAG_STARTED_BY_TILE, false)
)
service =
create(
Intent(FtpService.ACTION_START_FTPSERVER)
.putExtra(FtpService.TAG_STARTED_BY_TILE, false),
)

await().atMost(10, TimeUnit.SECONDS).until {
FtpService.isRunning() && isServerReady()
Expand All @@ -116,10 +116,11 @@ class FtpServiceEspressoTest {
.remove(FtpService.KEY_PREFERENCE_USERNAME)
.remove(FtpService.KEY_PREFERENCE_PASSWORD)
.commit()
service = create(
Intent(FtpService.ACTION_START_FTPSERVER)
.putExtra(FtpService.TAG_STARTED_BY_TILE, false)
)
service =
create(
Intent(FtpService.ACTION_START_FTPSERVER)
.putExtra(FtpService.TAG_STARTED_BY_TILE, false),
)

await().atMost(10, TimeUnit.SECONDS).until {
FtpService.isRunning() && isServerReady()
Expand All @@ -146,14 +147,15 @@ class FtpServiceEspressoTest {
FtpService.KEY_PREFERENCE_PASSWORD,
PasswordUtil.encryptPassword(
ApplicationProvider.getApplicationContext(),
"passw0rD"
)
"passw0rD",
),
)
.commit()
service = create(
Intent(FtpService.ACTION_START_FTPSERVER)
.putExtra(FtpService.TAG_STARTED_BY_TILE, false)
)
service =
create(
Intent(FtpService.ACTION_START_FTPSERVER)
.putExtra(FtpService.TAG_STARTED_BY_TILE, false),
)

await().atMost(10, TimeUnit.SECONDS).until {
FtpService.isRunning() && isServerReady()
Expand All @@ -176,7 +178,7 @@ class FtpServiceEspressoTest {
assertTrue(
"No files found on device? It is also possible that app doesn't have " +
"permission to access storage, which may occur on broken Android emulators",
files.isNotEmpty()
files.isNotEmpty(),
)
var downloadFolderExists = false
for (f in files) {
Expand All @@ -187,7 +189,7 @@ class FtpServiceEspressoTest {
assertTrue(
"Download folder not found on device. Either storage is not available, " +
"or something is really wrong with FtpService. Check logcat.",
downloadFolderExists
downloadFolderExists,
)
}

Expand Down Expand Up @@ -289,13 +291,14 @@ class FtpServiceEspressoTest {
}

private fun create(intent: Intent): FtpService {
val binder = serviceTestRule
.bindService(
intent.setClass(
ApplicationProvider.getApplicationContext(),
FtpService::class.java
val binder =
serviceTestRule
.bindService(
intent.setClass(
ApplicationProvider.getApplicationContext(),
FtpService::class.java,
),
)
)
return ((binder as ObtainableServiceBinder<FtpService>).service as FtpService).also {
it.onStartCommand(intent, 0, 0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import org.junit.runner.RunWith
@SmallTest
@RunWith(AndroidJUnit4::class)
class FtpServiceStaticMethodsTest {

/** To test [FtpService.getLocalInetAddress] must not return an empty string. */
@Test
fun testGetLocalInetAddressMustNotBeEmpty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ package com.amaze.filemanager.test
// import org.junit.Assert.assertTrue

object StoragePermissionHelper {

/**
* This method is intended for Android R or above devices to obtain MANAGE_EXTERNAL_STORAGE
* permission via UI Automator framework when running relevant Espresso tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import java.io.File

@RunWith(AndroidJUnit4::class)
class BackupPrefsFragmentTest {

var storagePath = "/storage/emulated/0"
var fileName = "amaze_backup.json"

Expand All @@ -63,7 +62,7 @@ class BackupPrefsFragmentTest {
File(
storagePath +
File.separator +
fileName
fileName,
)

exportFile.delete() // delete if already exists
Expand All @@ -80,7 +79,7 @@ class BackupPrefsFragmentTest {
File(
ApplicationProvider.getApplicationContext<Context>().cacheDir.absolutePath +
File.separator +
fileName
fileName,
)

Assert.assertTrue(tempFile.exists())
Expand Down Expand Up @@ -108,34 +107,37 @@ class BackupPrefsFragmentTest {
File(
storagePath +
File.separator +
fileName
fileName,
)

activityScenario.onActivity { preferencesActivity ->
preferencesActivity.supportFragmentManager.beginTransaction()
.add(backupPrefsFragment, null)
.commitNow()

val preferences = PreferenceManager
.getDefaultSharedPreferences(preferencesActivity)
val preferences =
PreferenceManager
.getDefaultSharedPreferences(preferencesActivity)

val preferenceMap: Map<String?, *> = preferences.all

val inputString = file
.inputStream()
.bufferedReader()
.use {
it.readText()
}
val inputString =
file
.inputStream()
.bufferedReader()
.use {
it.readText()
}

val type = object : TypeToken<Map<String?, *>>() {}.type

val importMap: Map<String?, *> = GsonBuilder()
.create()
.fromJson(
inputString,
type
)
val importMap: Map<String?, *> =
GsonBuilder()
.create()
.fromJson(
inputString,
type,
)

for ((key, value) in preferenceMap) {
var mapValue = importMap[key]
Expand All @@ -162,7 +164,7 @@ class BackupPrefsFragmentTest {
File(
storagePath +
File.separator +
fileName
fileName,
)

exportFile.delete() // delete if already exists
Expand All @@ -178,28 +180,31 @@ class BackupPrefsFragmentTest {
BackupPrefsFragment.IMPORT_BACKUP_FILE,
Activity.RESULT_OK,
Intent().setData(
Uri.fromFile(exportFile)
)
Uri.fromFile(exportFile),
),
)

val inputString = exportFile
.inputStream()
.bufferedReader()
.use {
it.readText()
}
val inputString =
exportFile
.inputStream()
.bufferedReader()
.use {
it.readText()
}

val type = object : TypeToken<Map<String?, *>>() {}.type

val importMap: Map<String?, *> = GsonBuilder()
.create()
.fromJson(
inputString,
type
)
val importMap: Map<String?, *> =
GsonBuilder()
.create()
.fromJson(
inputString,
type,
)

val preferences = PreferenceManager
.getDefaultSharedPreferences(preferencesActivity)
val preferences =
PreferenceManager
.getDefaultSharedPreferences(preferencesActivity)

val preferenceMap: Map<String?, *> = preferences.all

Expand All @@ -213,13 +218,14 @@ class BackupPrefsFragmentTest {
preferences: SharedPreferences,
importMap: Map<String?, *>,
key: String?,
value: Any?
value: Any?,
): Boolean {
when (value!!::class.simpleName) {
"Boolean" -> return importMap[key] as Boolean ==
preferences.getBoolean(key, false)
"Float" -> importMap[key] as Float ==
preferences.getFloat(key, 0f)
"Float" ->
importMap[key] as Float ==
preferences.getFloat(key, 0f)
"Int" -> {
// since Gson parses Integer as Double
val toInt = (importMap[key] as Double).toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ import kotlin.random.Random
@RunWith(AndroidJUnit4::class)
@Suppress("StringLiteralDuplication")
class CryptUtilEspressoTest {

@Rule @JvmField
val storagePermissionRule: GrantPermissionRule = GrantPermissionRule
.grant(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
val storagePermissionRule: GrantPermissionRule =
GrantPermissionRule
.grant(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)

/**
* Sanity test of CryptUtil legacy method, to ensure refactoring won't break
Expand All @@ -68,23 +68,24 @@ class CryptUtilEspressoTest {
ArrayList(),
"test.bin${CryptUtil.CRYPT_EXTENSION}",
false,
null
)
val targetFile = File(
Environment.getExternalStorageDirectory(),
"test.bin${CryptUtil.CRYPT_EXTENSION}"
null,
)
val targetFile =
File(
Environment.getExternalStorageDirectory(),
"test.bin${CryptUtil.CRYPT_EXTENSION}",
)
assertTrue(targetFile.exists())
if (SDK_INT < JELLY_BEAN_MR2) {
// Quirks for SDK < 18. File is not encrypted at all.
assertTrue(
"Source and target file size should be the same = ${source.size}",
source.size.toLong() == targetFile.length()
source.size.toLong() == targetFile.length(),
)
} else {
assertTrue(
"Source size = ${source.size} target file size = ${targetFile.length()}",
targetFile.length() > source.size
targetFile.length() > source.size,
)
}
sourceFile.delete()
Expand All @@ -96,7 +97,7 @@ class CryptUtilEspressoTest {
Environment.getExternalStorageDirectory().absolutePath,
ProgressHandler(),
ArrayList(),
null
null,
)
File(Environment.getExternalStorageDirectory(), "test.bin").run {
assertTrue(this.exists())
Expand All @@ -119,16 +120,17 @@ class CryptUtilEspressoTest {
ArrayList(),
"test.bin${CryptUtil.AESCRYPT_EXTENSION}",
true,
"12345678"
)
val targetFile = File(
Environment.getExternalStorageDirectory(),
"test.bin${CryptUtil.AESCRYPT_EXTENSION}"
"12345678",
)
val targetFile =
File(
Environment.getExternalStorageDirectory(),
"test.bin${CryptUtil.AESCRYPT_EXTENSION}",
)
assertTrue(targetFile.exists())
assertTrue(
"Source size = ${source.size} target file size = ${targetFile.length()}",
targetFile.length() > source.size
targetFile.length() > source.size,
)
sourceFile.delete()
CryptUtil(
Expand All @@ -139,7 +141,7 @@ class CryptUtilEspressoTest {
Environment.getExternalStorageDirectory().absolutePath,
ProgressHandler(),
ArrayList(),
"12345678"
"12345678",
)
File(Environment.getExternalStorageDirectory(), "test.bin").run {
assertTrue(this.exists())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import org.junit.runner.RunWith
@SmallTest
@RunWith(AndroidJUnit4::class)
class SecretKeygenEspressoTest {

/**
* Test [SecretKeygen.getSecretKey].
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RarExtractor(
filePath: String,
outputPath: String,
listener: OnUpdate,
updatePosition: UpdatePosition
updatePosition: UpdatePosition,
) : Extractor(context, filePath, outputPath, listener, updatePosition) {
override fun extractWithFilter(filter: Filter) {
// no-op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ import com.amaze.filemanager.filesystem.compressed.showcontents.Decompressor
class RarDecompressor(context: Context) : Decompressor(context) {
override fun changePath(
path: String,
addGoBackItem: Boolean
) =
UnknownCompressedFileHelperCallable(filePath, addGoBackItem)
addGoBackItem: Boolean,
) = UnknownCompressedFileHelperCallable(filePath, addGoBackItem)

override fun realRelativeDirectory(dir: String): String {
return ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import java.io.File
* For non Google Play variant, this class does nothing. Just a stub.
*/
object PackageInstallValidation {

/**
* Do nothing.
*/
Expand Down
Loading

0 comments on commit 45178b3

Please sign in to comment.