Skip to content

Instantly share code, notes, and snippets.

@lcacheux
lcacheux / mockitoEmptyStrings.kt
Created August 22, 2023 13:29
Let Mockito return empty strings instead of null
/**
* When Mockito mock methods or members that return String, the returned value is null, even when the return is
* non-nullable. This extension function will return empty strings instead of null for all cases.
*/
fun <T: Any> KStubbing<T>.returnEmptyStringsInsteadOfNulls() =
mock::class.members
.filter { it.returnType == typeOf<String>() || it.returnType == typeOf<String?>() }
.forEach { on { it.call(this) }.thenReturn("") }
@lcacheux
lcacheux / dircount.sh
Last active September 6, 2018 12:39
Small script to count files in all subdirectories
#!/bin/sh
for i in * .*; do
if [ -d "$i" ] && [ ".." != "$i" ]; then
dirname="$i"
dircount=`find "$i" | wc -l`
echo "$dircount\t$dirname"
fi
done