https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
announcements
  • u

    ubu

    01/26/2020, 2:05 PM
    hi there. could find any answer online: when will inline classes be stable?
    d
    b
    • 3
    • 3
  • c

    Chills

    01/26/2020, 3:01 PM
    looking for coroutines tutorial with out android crap!
    s
    • 2
    • 1
  • c

    Chills

    01/26/2020, 3:05 PM
    is coroutines are thread based or async/await based? as its coroutines so there is cooperation over routines but i can achieve concurrency via single thread similar to nodejs.
    l
    d
    s
    • 4
    • 19
  • b

    Bruno_

    01/26/2020, 3:23 PM
    would you place small variable wrapper in a dedicated file?
    data class Progress(val progress: Int, val max: Int)
    it's a function param in one of the services and only two more services will ever have to use it
    🇳🇴 5
    :yes: 1
    a
    h
    • 3
    • 8
  • c

    chansek

    01/26/2020, 3:29 PM
    Looks like a bug to me. Is it a bug or I am missing something?
    l
    • 2
    • 2
  • c

    Chills

    01/26/2020, 4:01 PM
    coroutine are really confusing
    z
    • 2
    • 5
  • c

    Chills

    01/26/2020, 4:44 PM
    will coroutine use single thread model or multi thread model behind the scene?
    a
    • 2
    • 1
  • r

    Ray Eldath

    01/26/2020, 7:01 PM
    small investigation: what is your most hateful Kotlin feature, from design point? and why? I go first:
    lateinit
    , only can be a
    var
    instead of
    val
    . and perhaps
    companion object
    , it's a good idea, but i think the syntax is not very good.(though i think i can't come up with a better design 😶)
    s
    c
    +4
    • 7
    • 28
  • p

    paulex

    01/27/2020, 12:46 AM
    Basically, how do i test a function like this
    fun foo(callback){
      GlobalScope.launch {
        val x = async {//}.await()
        callback(x)
      }
    }
    
    //Test
    @Test
    `test that we can test`(){
       //i should be able to test that callback is called with value x
    }
    e
    e
    • 3
    • 7
  • t

    thanksforallthefish

    01/27/2020, 8:46 AM
    however
    class Test{}
     class Another {
       fun <E: Any> test2(test: E) = test.test()
       fun <E: Any> E.test() = 
         println(javaClass.simpleName)
     }
     Another().test2(
       Test()
     )
    prints Test
    class Test{}
     class Another {
       fun <E: Any> test2(test: E) = test.test()
       fun <E: Any> E.test() = 
         println(this.javaClass.simpleName)
     }
     Another().test2(
       Test()
     )
    prints Test
    k
    • 2
    • 5
  • e

    elect

    01/27/2020, 10:33 AM
    is there another way I get a
    CharArray
    from an
    IntArray
    other than
    .let{ ints -> CharArray(ints.size){ints[it].toChar()}
    ?
    b
    d
    j
    • 4
    • 6
  • s

    steenooo

    01/27/2020, 12:57 PM
    Uhm, I wasnt really able to find this online, but. I was wondering what the naming conventions were for Kotlin files. I’ve seen alot of differing things
    s
    m
    • 3
    • 2
  • i

    iex

    01/27/2020, 1:21 PM
    Hi! Any ideas why this doesn't compile? Hope it's fine to put rx code here. It's a lang question.
    fun foo(): Observable<Result<String, String>> =
        Observable.just(Success(""))
            .onErrorResumeNext { t: Throwable -> Failure("") } // Type mismatch: inferred type is Observable<Result.Success<String>!>! but Observable<Result<String, String>> was expected
    
    // where:
    
    sealed class Result<out T, out E> {
        data class Success<out T>(val success: T) : Result<T, Nothing>()
        data class Failure<out E>(val error: E) : Result<Nothing, E>()
    }
    d
    • 2
    • 8
  • m

    Matsushita Kohei

    01/27/2020, 2:45 PM
    Hi everybody , When will a coroutine flow be less experimental? If anyone knows please tell me
    ➕ 1
    r
    • 2
    • 2
  • b

    Big Chungus

    01/27/2020, 3:21 PM
    Is there a way to set default visibility to
    internal
    via gradle or compiler arg?
    🇳🇴 2
    b
    • 2
    • 1
  • n

    nfrankel

    01/27/2020, 4:40 PM
    i don’t know about you but i feel the quality of the kotlin slack has degraded a lot over several months • asking questions completely unrelated to kotlin • posting in several channels to get more attention • etc. am i the only one to feel that way?
    ➕ 10
    r
    d
    +6
    • 9
    • 23
  • c

    Chills

    01/27/2020, 10:34 PM
    any thoughts on this in intellij IDE Error: Could not find or load main class FooKt Caused by: java.lang.ClassNotFoundException: FooKt
    k
    • 2
    • 1
  • j

    jimn

    01/28/2020, 7:57 AM
    is inline class overhead the same if it is just an inline class with 0 methods and accessors, or if it has 1+ method, accessor, or implements interface?
    d
    • 2
    • 6
  • o

    Obaid Jatoi

    01/28/2020, 10:14 AM
    Hello all, We want to start with Kotlin multiplatform, Can anyone please tell me that what is the scope of third party apps? I mean if there is any third party analytic SDK which currently we are using on native android and IOS, how we will accommodate these SDK'S with Kotlin multiplatform library or project you can say ?
    a
    • 2
    • 2
  • r

    Rodrigo Silva

    01/28/2020, 1:45 PM
    Hello everyone. I'm trying to create an abstract kafka consumer with kotlin, with no luck. If anyone can help: https://stackoverflow.com/questions/59950147/make-na-abstraction-to-kafka-consumer-using-ktor-and-kotlin
    e
    • 2
    • 2
  • g

    Georgi Naumov

    01/28/2020, 2:38 PM
    Would someone give me an example how to get timezone offset in milliseconds?
    • 1
    • 1
  • k

    Kroppeb

    01/28/2020, 6:58 PM
    Why can't I take out the subclasses of a sealed type outside of the class definition in script files, like you can do with normal Kotlin files?
    c
    • 2
    • 1
  • t

    Tommi Reiman

    01/28/2020, 8:50 PM
    Hi. I'm a Kotlin newbie and interested in hearing is it possible to have an utility to deep-merge two data class instances of same type? Failed on inline + recursion...
    c
    • 2
    • 10
  • s

    Slackbot

    01/29/2020, 12:19 AM
    This message was deleted.
    a
    • 2
    • 1
  • v

    victor-mntl

    01/29/2020, 7:12 AM
    Running BeakerX (Jupyter Notebook w/ Kotlin support) I find this warn when the Kotlin kernel starts:
    WARN: Failed to initialize native filesystem for Windows
    java.lang.RuntimeException: Could not find installation home path. Please make sure bin/idea.properties is present in the installation directory.
    at <http://org.jetbrains.kotlin.com|org.jetbrains.kotlin.com>.intellij.openapi.application.PathManager.getHomePath(PathManager.java:97) (...)
    Looks like a common issue in other projects that is solved using
    System.setProperty("<http://idea.io|idea.io>.use.fallback", "true")
    or
    System.setProperty("idea.use.native.fs.for.win", "false")
    called before
    KotlinCoreEnvironment.createForProduction
    e.g.: https://github.com/arturbosch/detekt/issues/630 Is it something wrong? Anything missing on my side?
    a
    • 2
    • 3
  • r

    Ray Eldath

    01/29/2020, 7:26 AM
    any idea about database affairs in kotlin? exposed is gonna kill me... 😣 i think i will turn for dbutils eventually... though i do really like exposed... 😞
    a
    m
    • 3
    • 5
  • l

    luke

    01/29/2020, 9:03 AM
    In bytecode, does a
    suspend fun
    only ever return a
    java/lang/Object
    ? Can't seem to make it typed.
    m
    k
    • 3
    • 4
  • b

    Big Chungus

    01/29/2020, 9:21 AM
    FYI: If any of you uses Hazelcast, you might've come to a point where you just need to check what actual data the cluster contains or make a small modification to some entry for either testing or development purposes? No more writing up shell unit test to stop the debugger and use that environment to achieve said tasks. I've written up an easily configurable (via Kotlin DSL) library to provide you a quick and direct access to Hazelcast cluster data via a prebuilt embedded webapp. See the project and example setup here: https://gitlab.com/lt.petuska/hazelcast-explorer Hope this will help to speed up your development/testing (as it surely did ours)! As always, any questions -> DM me.
    ❤️ 1
    👍 2
    j
    • 2
    • 4
  • j

    Jiri Bruchanov

    01/29/2020, 10:31 AM
    Morning, anyone who could help me with "tricky" function call ?
    d
    • 2
    • 6
  • t

    tschuchort

    01/29/2020, 1:35 PM
    What's the conventional wisdom on mockito-kotlin vs MockK? I feel like mockito-kotlin is more intuitive
    m
    e
    k
    • 4
    • 16
Powered by Linen
Title
t

tschuchort

01/29/2020, 1:35 PM
What's the conventional wisdom on mockito-kotlin vs MockK? I feel like mockito-kotlin is more intuitive
m

Mike

01/29/2020, 1:43 PM
Don't know about conventional, but this has been my approach. But bottom-line, they are both excellent, and more alike than different. If you work with both Java and Kotlin, I'd suggest sticking with Mockito as you can leverage knowledge you already have, and reduce training effort of people joining a mixed team. If you're mostly/all Kotlin, and want to test some of the features MockK supports, then use it. If you want your tool chain as Kotlin as possible, then again, choose MockK.
t

tschuchort

01/29/2020, 2:13 PM
What does MockK do better than mockito-kotlin and vice versa? From what I can tell they are both absolute crap or maybe I'm just too stupid to use them. Mockito-kotlin simply crashes when you wrap a matcher in
not()
which means you can't verify that an argument is not equal to something with using
argWhere { ... }
. MockK's API is completely asinine. Who thought
verify(exactly = 1, atLeast = 2)
would be a good idea? MockK also lacks Mockito's
check
matcher. And neither seem to allow me to verify that all calls to a function satisfy a predicate. Mockito has
verifyAll
of course but that applies to all methods and not just one. So for an n-argument method you end up writing n+1 separate
verify
clauses: One to verify the positive case and n to verify the negative case for each argument.
m

Mike

01/29/2020, 2:36 PM
I'll be blunt. I don't think your approach is the best. You're creating too tight a coupling between the tests and the implementation. You should be testing the inputs, and outputs, and not care too much how the called function is doing its thing. Otherwise you can't safely refactor the implementation as you're changing both the test and the implementation. Having said that, Mockito can come closer to what I think you want if you're using JUnit4/5, and you use the Mockito Rule/Extension and Strict verification of mocks. Basically, if you define a mock, and an interaction on it, then the extension will ensure that ALL defined interactions are called, and that ONLY the defined interactions were called. If you define a mock, but NO interactions on it, then Mockito won't do the above verifications. So that's an edge case to be aware of. But I believe there's a 'noMoreInteractions' for that scenario. I don't think MockK supports that level of strictness right now. HTH
Just re-reading. Have you seen the 'noMoreInteractions' function on Mockito? I think that's exactly what you're looking for and will work regardless of test framework. https://mincong.io/2019/09/22/mockito-verify/#verify-interaction-with-other-methods Of course author has same opinion I do:
Personally, I don’t recommend this kind of verification because it is too strict: it means that you don’t trust the actual implementation and the test needs to be updated frequently, every time when more interaction is added with the target mock object.
t

tschuchort

01/29/2020, 2:49 PM
verifyNoMoreInteractions
won't work here because it also excludes calls to other methods of the mock. I want to verify: any number of calls to any method except
foo
and at least one call to
foo
with parameter
x
and for all calls to
foo
parameter is
x
. Or in pseudocode:
val callsToFoo = calls.filter { it.methodName == "foo" }
assert(callsToFoo.all { it.argument == "x" } && callsToFoo.size >= 1)
Another thing about MockK: Why is there both
verify(inverse = true)
and
verify(exactly = 0)
. Shouldn't they be the same?
m

Mike

01/29/2020, 2:58 PM
I'm not real familiar with MockK, but guessing you can define some mock interactions, but put
inverse = true
and it would ensure that those aren't called. And because of possible parameters, you'll just end up with some equivalencies.
Can you do something like this?
//argument matchers can also be written as Java 8 Lambdas
 verify(mockedObject).foo(argThat(someString -> someString == "X"));
From: https://javadoc.io/static/org.mockito/mockito-core/3.2.4/org/mockito/Mockito.html#argument_matchers
e

Erik

01/29/2020, 4:42 PM
If you ask for opinions, here's mine: I think MockK is more intuitive, because it leads to more idiomatic Kotlin which arguably is more intuitive.
Note that MockK also has something similar to
verifyNoMoreInteractions
, called
confirmVerified
. You can verify that you've verified all recorded interactions with your mocks.
t

tschuchort

01/29/2020, 8:28 PM
You can use
argThat
instead of
not
but it's not really convenient
confirmVerified
wont work because I only want to verify all interactions on one method not on all methods
k

kyleg

01/30/2020, 5:02 AM
I prefer MockK. The criticisms I’m seeing above of MockK should properly be classified as “fails to protect a stupid dev from themselves” rather than “does stupid stuff itself.” I write only in Kotlin, never in Java, and I kept running into things where Mockito couldn’t do something I needed it to do. It’s been a few months now, so I can’t remember what they were.
e

Erik

01/30/2020, 7:42 AM
Agreed. If testing and writing testable code are done correctly, then MockK is a great tool to do the mocking. With any mocking lib, be it Mockito or MockK or any other, you can simply do it wrong and end up testing that you've set up your mocks correctly, instead of testing your testable code's behaviour.
t

tschuchort

01/30/2020, 12:57 PM
IMO a library should be designed to make misuse impossible and to be discoverable without documentation. Neither Mockito nor MockK fulfill these criteria unfortunately.
m

Mike

01/30/2020, 1:46 PM
That's a good ideal, but unfortunately when it comes to testing, there isn't a concrete definition of 'misuse', or 'good use'. So if the library wants to be used, it unfortunately ends up being too flexible, and requires team guidelines/rules...
View count: 26