Capturing arguments with mockito

EncryptedFileInfo info = cut.storeEncryptedFile(encryptionSecret, plainContents, fileName);

ArgumentCaptor<byte[]> argument = ArgumentCaptor.forClass(byte[].class);

verify(cut).createFileAndAdd(eq(fileName), argument.capture());
byte[] encryptedContent = argument.getAllValues().get(0);

Where intercepted method is:

void createFileAndAdd(String fileName, byte[] encryptedContents);

Bootstraping Spring core using the context

AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

At this point al found beans has been registered and can be used. As an example code would go further as follows, taking care that ExStateMachine.class  is annotated as @Component :

ExStateMachine machine = context.getBeanFactory().getBean(ExStateMachine.class);


There are several available conext, all implementing the interface:


package org.springframework.context.annotation:


package org.springframework.jca.context:

Runing test from jar with Junit5

java -jar junit-platform-console-standalone-1.3.0-M1.jar -n .*IT -scan-class-path -cp target\test-classes\(test.jar) -cp target\app-jar-with-dependencies.jar
  • -n .*IT is a regex looking for files suffixed with IT (default: ^(Test.*|.+[.$]Test.*|.*Tests?)$)
  • -scan-class-path look for tests on classpath
  • -cp: the classpath


to compile test classes:  mvn test-compile compile

to create test jar:


AWK useful commands

  1. print column n using a separator #awk -F# ‘{print $n}’
  2. print column 3 of lines that start with a number.: awk ‘/^[0-9]/ {print $3}’
  3. Variables:
    • NF: number of fields
    • NR: Number of record being processed
      • Avoid first record(row) and print last field (columnd): awk ‘{if(NR>1) print $NF}’: 

More about built-in variables: 8 Powerful Awk Built-in Variables

Some more tricks:

Hamcrest matchers

  • Hamcrest collections:
    • Package: org.hamcrest.collection
      • Javadoc:
      • Check not empty collections:
assertThat(someCollection, not(IsEmptyCollection.empty()));
  • Pacakge: org.hamcrest.core:
    • IsCollectionContaining.hasItem:
assertThat(list, hasItem(item));