Skip to content

Instantly share code, notes, and snippets.

@jlorenzen
jlorenzen / kotlin-coroutine-scratch.kt
Last active April 20, 2022 16:18
kotlin-coroutines
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.time.LocalDateTime
fun printWithDatePrefix(msg: String) =
println("${LocalDateTime.now()} : $msg")
suspend fun fetchItems(): List<String> {
printWithDatePrefix("starting fetch")
@jlorenzen
jlorenzen / json-logging-with-runtime-appender.md
Last active October 1, 2021 15:41
Set logback appender with json at runtime
@jlorenzen
jlorenzen / readme.md
Created February 2, 2021 15:02
Reasons to stop using Mockito's @Injectmocks

When I first started using Mockito to mock out objects in java tests I almost always used the @InjectMocks annotation to construct the CUT (Class Under Test). But after using it for awhile and noticing some downsides I've since stopped using it altogether.

Here is a list of reasons why:

  • Less magical
  • There are some occasions where I need to be in control of what gets injected so constructing the CUT manually keeps all the tests consistent
  • In some tests, I don’t end up verifying some mocks are invoked because it’s internal stuff. When this happens Idea flags them as unused even though they are technically necessary to construct a valid CUT.
  • I think it can sometimes hide a class that has too much responsibility. If you have a large construction line that should be a clue your class is doing too much.
  • If you use it it would be real easy to forget to remove the mock in the test
@jlorenzen
jlorenzen / gist:aad348bc311c7ff0c0f4
Created October 16, 2014 05:23
colored git branch in terminal
function parse_git_branch_prompt {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "["${ref#refs/heads/}"]"
}
MAGENTA="\[\e[0;35m\]"
WHITE="\[\033[0m\]"
RED="\[\033[0;31m\]"
DARK_YELLOW="\[\033[0;33m\]"
BLUE="\[\e[0;34m\]"
# thanks to this gist for the iTerm2 tab naming stuff: https://gist.github.com/phette23/5270658
# can't remember where I cribbed the rest of this from!
# hacked it a bit to work on OS X
_bold=$(tput bold)
_normal=$(tput sgr0)
__vcs_dir() {
local vcs base_dir sub_dir ref
sub_dir() {
@jlorenzen
jlorenzen / tidy xml
Created June 3, 2014 14:59
tidy xml example
tidy -xml -im --indent-spaces 4 m2/settings.xml
[user]
name = Pavan Kumar Sunkara
email = pavan.sss1991@gmail.com
[core]
editor = vim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore
[sendemail]
smtpencryption = tls
smtpserver = smtp.gmail.com
git diff 4ac8c94a6f758b480a3c18614be1de921b4c2547^..4ac8c94a6f758b480a3c18614be1de921b4c2547 src/test/groovy/com/accenture/netcds/tck/aircraft/ServiceWebServiceTest.groovy
@jlorenzen
jlorenzen / project-release.sh
Created May 15, 2010 03:14
script used to release a project
#!/bin/bash
# http://jlorenzen.blogspot.com/2010/05/how-to-create-release-without-maven2.html
echo -e "Usage ./project-release.sh [n] [dryRun]\n"
INCREMENT_POS=$1
DRY_RUN=$2
DEST_BASE_URL=https://server/svn/project/branches
BASE_MSG="[project-release.sh] -"
CREATE_BRANCH_MSG="$BASE_MSG Creating Branch"