Fix Kotlin coding style

This commit is contained in:
Torsten Grote
2021-08-31 14:32:36 +02:00
parent d8267ce559
commit f3273260bb
9 changed files with 48 additions and 29 deletions

View File

@@ -33,6 +33,7 @@
</option>
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
@@ -185,5 +186,11 @@
</rules>
</arrangement>
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>

View File

@@ -37,7 +37,7 @@ constructor(
?: throw UsageError("Could not get password. Is STDIN connected?")
try {
accountManager.signIn(password)
} catch (e : DecryptionException) {
} catch (e: DecryptionException) {
echo("Error: Password invalid")
exitProcess(1)
}

View File

@@ -3,7 +3,11 @@ package org.briarproject.briar.headless
import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.databind.ObjectMapper
import io.javalin.Javalin
import io.javalin.apibuilder.ApiBuilder.*
import io.javalin.apibuilder.ApiBuilder.delete
import io.javalin.apibuilder.ApiBuilder.get
import io.javalin.apibuilder.ApiBuilder.path
import io.javalin.apibuilder.ApiBuilder.post
import io.javalin.apibuilder.ApiBuilder.put
import io.javalin.core.security.AccessManager
import io.javalin.core.util.Header.AUTHORIZATION
import io.javalin.http.BadRequestResponse

View File

@@ -6,16 +6,16 @@ import org.briarproject.briar.api.blog.MessageType
import org.briarproject.briar.headless.json.JsonDict
internal fun BlogPostHeader.output(text: String) = JsonDict(
"text" to text,
"author" to author.output(),
"authorStatus" to authorInfo.status.output(),
"type" to type.output(),
"id" to id.bytes,
"parentId" to parentId?.bytes,
"read" to isRead,
"rssFeed" to isRssFeed,
"timestamp" to timestamp,
"timestampReceived" to timeReceived
)
"text" to text,
"author" to author.output(),
"authorStatus" to authorInfo.status.output(),
"type" to type.output(),
"id" to id.bytes,
"parentId" to parentId?.bytes,
"read" to isRead,
"rssFeed" to isRssFeed,
"timestamp" to timestamp,
"timestampReceived" to timeReceived
)
internal fun MessageType.output() = name.toLowerCase()

View File

@@ -2,7 +2,11 @@ package org.briarproject.briar.headless.contact
import org.briarproject.bramble.api.contact.PendingContact
import org.briarproject.bramble.api.contact.PendingContactState
import org.briarproject.bramble.api.contact.PendingContactState.*
import org.briarproject.bramble.api.contact.PendingContactState.ADDING_CONTACT
import org.briarproject.bramble.api.contact.PendingContactState.CONNECTING
import org.briarproject.bramble.api.contact.PendingContactState.FAILED
import org.briarproject.bramble.api.contact.PendingContactState.OFFLINE
import org.briarproject.bramble.api.contact.PendingContactState.WAITING_FOR_CONNECTION
import org.briarproject.bramble.api.contact.event.PendingContactAddedEvent
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent
import org.briarproject.bramble.api.contact.event.PendingContactStateChangedEvent
@@ -14,7 +18,7 @@ internal fun PendingContact.output() = JsonDict(
"timestamp" to timestamp
)
internal fun PendingContactState.output() = when(this) {
internal fun PendingContactState.output() = when (this) {
WAITING_FOR_CONNECTION -> "waiting_for_connection"
OFFLINE -> "offline"
CONNECTING -> "connecting"

View File

@@ -14,7 +14,12 @@ import org.briarproject.bramble.api.identity.LocalAuthor
import org.briarproject.bramble.api.sync.Group
import org.briarproject.bramble.api.sync.Message
import org.briarproject.bramble.api.system.Clock
import org.briarproject.bramble.test.TestUtils.*
import org.briarproject.bramble.test.TestUtils.getAuthor
import org.briarproject.bramble.test.TestUtils.getClientId
import org.briarproject.bramble.test.TestUtils.getContact
import org.briarproject.bramble.test.TestUtils.getGroup
import org.briarproject.bramble.test.TestUtils.getLocalAuthor
import org.briarproject.bramble.test.TestUtils.getMessage
import org.briarproject.bramble.util.StringUtils.getRandomString
import org.briarproject.briar.api.conversation.ConversationManager
import org.briarproject.briar.headless.event.WebSocketController

View File

@@ -48,31 +48,31 @@ abstract class IntegrationTest {
dataDir.deleteRecursively()
}
protected fun get(url: String) : Response {
protected fun get(url: String): Response {
return khttp.get(url, getAuthTokenHeader(token))
}
protected fun getWithWrongToken(url: String) : Response {
protected fun getWithWrongToken(url: String): Response {
return khttp.get(url, getAuthTokenHeader("wrongToken"))
}
protected fun post(url: String, data: String) : Response {
protected fun post(url: String, data: String): Response {
return khttp.post(url, getAuthTokenHeader(token), data = data)
}
protected fun postWithWrongToken(url: String) : Response {
protected fun postWithWrongToken(url: String): Response {
return khttp.post(url, getAuthTokenHeader("wrongToken"), data = "")
}
protected fun delete(url: String) : Response {
protected fun delete(url: String): Response {
return khttp.delete(url, getAuthTokenHeader(token))
}
protected fun delete(url: String, data: String) : Response {
protected fun delete(url: String, data: String): Response {
return khttp.delete(url, getAuthTokenHeader(token), data = data)
}
protected fun deleteWithWrongToken(url: String) : Response {
protected fun deleteWithWrongToken(url: String): Response {
return khttp.delete(url, getAuthTokenHeader("wrongToken"))
}

View File

@@ -8,7 +8,7 @@ import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
class ContactControllerIntegrationTest: IntegrationTest() {
class ContactControllerIntegrationTest : IntegrationTest() {
@Test
fun `returning list of contacts needs authentication token`() {
@@ -24,7 +24,7 @@ class ContactControllerIntegrationTest: IntegrationTest() {
assertEquals(0, response.jsonArray.length())
// add one test contact
val testContactName= "testContactName"
val testContactName = "testContactName"
testDataCreator.addContact(testContactName, true, false)
// retrieve list with one test contact

View File

@@ -1,8 +1,6 @@
package org.briarproject.briar.headless.contact
import io.javalin.http.BadRequestResponse
import io.javalin.http.ForbiddenResponse
import io.javalin.http.HttpResponseException
import io.javalin.http.NotFoundResponse
import io.javalin.plugin.json.JavalinJson.toJson
import io.mockk.Runs
@@ -35,7 +33,6 @@ import org.briarproject.bramble.util.StringUtils.getRandomString
import org.briarproject.briar.headless.ControllerTest
import org.briarproject.briar.headless.getFromJson
import org.briarproject.briar.headless.json.JsonDict
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.Test
@@ -316,7 +313,9 @@ internal class ContactControllerTest : ControllerTest() {
fun testSetContactAliasInvalid() {
mockkStatic("org.briarproject.briar.headless.RouterKt")
every { ctx.pathParam("contactId") } returns "1"
every { ctx.getFromJson(objectMapper, "alias") } returns getRandomString(MAX_AUTHOR_NAME_LENGTH + 1)
every {
ctx.getFromJson(objectMapper, "alias")
} returns getRandomString(MAX_AUTHOR_NAME_LENGTH + 1)
assertThrows(BadRequestResponse::class.java) {
controller.setContactAlias(ctx)
}