Replace to upper/low case with regex

\U$1 will set all chars contained into group $1 to upper case.

\U$1 will set the first char of the group $1 to upper case.

\L$1 will set all chars contained into group $1 to upper case.

\l$1 will set the first char of the group $1 to lower case.

E.g.

SOME_TEXT against regex _([a-z]+) replaced by \l$1 will produce SOME_tEXT

SOME_TEXT against regex _([a-z]+) replaced by \L$1 will produce SOME_text

 

 

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();
context.scan("tech.lacambra.prototype.statesmachine");
context.refresh();

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);
machine.doSignals();

System.out.println("done!");

There are several available conext, all implementing the interface:

org.springframework.context.ApplicationContext
org.springframework.context:
ConfigurableApplicationContext.java

package org.springframework.context.annotation:
 AnnotationConfigApplicationContext.java

package org.springframework.context.support:
 AbstractApplicationContext.java
 AbstractRefreshableApplicationContext.java
 AbstractRefreshableConfigApplicationContext.java
 AbstractXmlApplicationContext.java
 ClassPathXmlApplicationContext.java
 FileSystemXmlApplicationContext.java
 GenericApplicationContext.java
 GenericGroovyApplicationContext.java
 GenericXmlApplicationContext.java
 StaticApplicationContext.java

package org.springframework.jca.context:
 ResourceAdapterApplicationContext.java

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
where:
  • -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

Bonus:

to compile test classes:  mvn test-compile compile

to create test jar:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <goals>
                <goal>test-jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>