Skip to content

Commit

Permalink
IDE-251 Fix all detekt warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
coki1405 committed Jul 10, 2024
1 parent 1a4dde7 commit 438c3a8
Show file tree
Hide file tree
Showing 54 changed files with 705 additions and 412 deletions.
5 changes: 3 additions & 2 deletions catroid/config/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ complexity:
threshold: 80
LongParameterList:
active: true
threshold: 6
functionThreshold: 8
constructorThreshold: 8
ignoreDefaultParameters: false
MethodOverloading:
active: true
threshold: 2
threshold: 6
NestedBlockDepth:
active: true
threshold: 4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -100,7 +100,7 @@ class BrickContextMenuTest(
arrayOf(WhenNfcBrick(), false, false),
arrayOf(WhenRaspiPinChangedBrick(), false, false),
arrayOf(WhenTouchDownBrick(), false, false)
)
)
}

@Before
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -79,14 +79,18 @@ class DeleteImportedSpriteTest {
baseActivityTestRule.launchActivity()
Intents.init()

expectedIntent = AllOf.allOf(IntentMatchers.hasExtra(
ProjectListActivity.IMPORT_LOCAL_INTENT,
baseActivityTestRule.activity.getString(R.string.import_sprite_from_project_launcher)
))
expectedIntent = AllOf.allOf(
IntentMatchers.hasExtra(
ProjectListActivity.IMPORT_LOCAL_INTENT,
baseActivityTestRule.activity.getString(R.string.import_sprite_from_project_launcher)
)
)

val resultData = Intent()
resultData.putExtra(ProjectListActivity.IMPORT_LOCAL_INTENT,
localProject.directory.absoluteFile.absolutePath)
resultData.putExtra(
ProjectListActivity.IMPORT_LOCAL_INTENT,
localProject.directory.absoluteFile.absolutePath
)

val result = Instrumentation.ActivityResult(Activity.RESULT_OK, resultData)
Intents.intending(expectedIntent).respondWith(result)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -52,11 +52,11 @@ class ScreenshotSaverTest(private val name: String, private val fileName: String
@JvmStatic
@Parameterized.Parameters(name = "{0}")
fun data() = listOf(
arrayOf("VALID", "valid.png", true),
arrayOf("NULL", null, false),
arrayOf("WHITESPACES", " ", false),
arrayOf("ILLEGAL_CHARACTERS", "|\\?*<\":>+[]/'", false)
)
arrayOf("VALID", "valid.png", true),
arrayOf("NULL", null, false),
arrayOf("WHITESPACES", " ", false),
arrayOf("ILLEGAL_CHARACTERS", "|\\?*<\":>+[]/'", false)
)

private const val NUMBER_OF_COLORS = 4
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -103,8 +103,14 @@ class BrickSearchTest {
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
viewMatcher.perform(pressKey(KeyEvent.KEYCODE_ENTER))
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
Espresso.onData(Matchers.allOf(Matchers.`is`(Matchers.instanceOf
(bricks[index] as Class<*>?))))
Espresso.onData(
Matchers.allOf(
Matchers.`is`(
Matchers.instanceOf
(bricks[index] as Class<*>?)
)
)
)
.inAdapterView(BrickPrototypeListMatchers.isBrickPrototypeView())
.atPosition(0)
.check(matches(isDisplayed()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -115,13 +115,9 @@ class AssertEqualsBrickTest {

private fun handleConstraints(action: ViewAction, constraints: Matcher<View>): ViewAction {
return object : ViewAction {
override fun getConstraints(): Matcher<View> {
return constraints
}
override fun getConstraints(): Matcher<View> = constraints

override fun getDescription(): String {
return action.description
}
override fun getDescription(): String = action.description

override fun perform(uiController: UiController?, view: View?) {
action.perform(uiController, view)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -67,12 +67,12 @@ class StartListeningStageTest {
@Before
fun setUp() {
createProject(javaClass.simpleName)
textToSpeech = TextToSpeech(ApplicationProvider.getApplicationContext(), TextToSpeech.OnInitListener
{ status ->
if (status == TextToSpeech.SUCCESS) {
textToSpeech.language = Locale.US
textToSpeech =
TextToSpeech(ApplicationProvider.getApplicationContext()) { status ->
if (status == TextToSpeech.SUCCESS) {
textToSpeech.language = Locale.US
}
}
})
baseActivityTestRule.launchActivity(null)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -111,8 +111,8 @@ class TextDetectionResourceTest {

val script = UiTestUtils.createProjectAndGetStartScript("TextDetectionResourceTest")
.also {
it.addBrick(SetSizeToBrick(formula))
}
it.addBrick(SetSizeToBrick(formula))
}
lastBrickInScript = ScriptEvaluationGateBrick.appendToScript(script)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -126,6 +126,7 @@ import org.junit.runners.Parameterized
@Category(AppUi::class, Smoke::class)
@RunWith(Parameterized::class)
class FormulaEditorComputeDialogComputationResultTest(
@Suppress("unused")
private val name: String,
private val formula: Formula,
private val userVariableLeftValue: Any?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -209,12 +209,18 @@ class MergeLocalSpriteTest {
val mergedSoundList = mergedSprite.soundList
val mergedLookList = mergedSprite.lookList

Assert.assertEquals(sprite1.lookList.size + sprite2.lookList.size,
mergedLookList.size)
Assert.assertEquals(sprite1.scriptList.size + sprite2.scriptList.size,
mergedScriptList.size)
Assert.assertEquals(sprite1.soundList.size + sprite2.soundList.size,
mergedSoundList.size)
Assert.assertEquals(
sprite1.lookList.size + sprite2.lookList.size,
mergedLookList.size
)
Assert.assertEquals(
sprite1.scriptList.size + sprite2.scriptList.size,
mergedScriptList.size
)
Assert.assertEquals(
sprite1.soundList.size + sprite2.soundList.size,
mergedSoundList.size
)
}

private fun assertOriginalIntact(originalSprite: Sprite, currentSprite: Sprite) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -93,7 +93,9 @@ object TrustedDomainManager {
val domains = trustList.getJSONArray(TRUST_LIST_JSON_ARRAY_NAME)
cleanUpUserInput(domains.join("\n"))
}
} else ""
} else {
""
}
} catch (e: IOException) {
Log.e(TAG, READ_ERROR_LOG, e)
""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -34,7 +34,9 @@ class EventWrapperListener internal constructor(private val look: Look) : EventL
if (event is EventWrapper) {
handleEvent(event)
true
} else false
} else {
false
}

private fun handleEvent(event: EventWrapper) {
with(look) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -55,18 +55,21 @@ class ParameterizedAssertAction : AssertAction() {
parameterizedData?.let { data ->
if (!equalValues(actualValue, expectedValue.toString())) {
data.failMessages.append("\n${data.currentParameters}\n").append(
formattedAssertEqualsError(actualValue, expectedValue))
formattedAssertEqualsError(actualValue, expectedValue)
)
} else {
data.successMessages.append("\n${data.currentParameters}\n").append(
formattedSuccessMessage(actualValue, expectedValue))
formattedSuccessMessage(actualValue, expectedValue)
)
}

data.currentPosition++
data.currentParameters = ""

if (data.failMessages.isNotEmpty() &&
data.currentPosition >= expectedList?.value?.size ?: 0) {
failWith("Failed Tests:\n${data.failMessages}\n\nSucceeded Tests:\n${data.successMessages}")
data.currentPosition >= expectedList?.value?.size ?: 0
) {
failWith("Failed Tests:\n${data.failMessages}\n\nSucceeded Tests:\n${data.successMessages}")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -81,9 +81,9 @@ class PlaySoundAtAction : TemporalAction() {
if (sprite.soundList.contains(sound)) {

sound?.let {
manager.playSoundFileWithStartTime(
it.file.absolutePath, sprite, offsetMilliseconds
)
manager.playSoundFileWithStartTime(
it.file.absolutePath, sprite, offsetMilliseconds
)
}
return manager.getDurationOfSoundFile(sound?.file?.absolutePath) - offsetMilliseconds
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -35,6 +35,8 @@ open class SetLookAction : MultiSpriteEventAction() {
return if (lookData != null && sprite?.lookList?.contains(lookData) == true) {
sprite!!.look.lookData = lookData
SetLookEventId(sprite, lookData)
} else null
} else {
null
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -37,7 +37,9 @@ abstract class SetRelativeLookAction : SetLookByIndexAction() {
(look.lookListIndexBeforeLookRequest + change + lookList.size) % lookList.size
} else if (currentLookData != null && lookList?.contains(currentLookData) == true) {
(lookList.indexOf(currentLookData) + change + lookList.size) % lookList.size
} else 0
} else {
0
}
formula = Formula(newIndex + 1)
look?.lookListIndexBeforeLookRequest = -1
return super.getEventId()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -58,7 +58,9 @@ abstract class WebAction : Action(), WebRequestListener {
formula!!.interpretString(scope)!!.let {
url = if (it.startsWith("http://") || it.startsWith("https://")) {
it
} else "https://$it"
} else {
"https://$it"
}
}
val newlineIndex = url?.indexOf("\n")
if (newlineIndex != -1) {
Expand Down Expand Up @@ -134,7 +136,9 @@ abstract class WebAction : Action(), WebRequestListener {
return if (stageListener.webConnectionHolder.addConnection(webConnection!!)) {
webConnection!!.sendWebRequest()
true
} else false
} else {
false
}
}

abstract fun handleResponse()
Expand Down
Loading

0 comments on commit 438c3a8

Please sign in to comment.