Java JUnit: Reset a singleton
28 February 2018
Java singleton's are hard to unit test because the state of the singleton is altered as each test runs. But for testing sake you can reset the singleton's state use reflection. Here is an example that worked for me.
@Before public void setup() throws NoSuchFieldException, IllegalAccessException { Field instance = RemoteMessageTranslation.class.getDeclaredField("set"); instance.setAccessible(true); instance.setBoolean(null, false); }
I hope this helps
Read : Java JUnit: Reset a singleton
Java Regex Pattern Within a String
01 February 2018
Here is how to find a Java regex pattern within a string.
@Test public void stringContainsRegexPattern() { assertTrue(Pattern.compile("pattern(?:\\s[a-z]+){2}\\setc\\.").matcher("Here is the pattern and that etc.").find()); }
Read : Java Regex Pattern Within a String
The Java 8 Lambda way: ArrayList to an Array
15 July 2016
In an earlier post this year, 'Convert an ArrayList to an Array in Java', I commented on a way to convert an ArrayList to an Array in Java. Here is the example code from the earlier post.
List<String> results = new ArrayList<>(); ... results.toArray(new String[results.size()]);
This earlier way works fine, however it's old school. Here is the Java 8 Lambda way to convert an ArrayList to an Array:
Long[] longArray = longArrayList.stream() .map(Long::new) .toArray(Long[]::new);
This example works by mapping a new object for each item in the ArrayList's stream to the new stream, and then collecting that stream as an array.
Read : The Java 8 Lambda way: ArrayList to an Array
Devoxx Poland 2016
09 June 2016
I am very happy to be attending Devoxx Poland 2016; I enjoyed Devoxx Poland last year very much. As well as Krakow.

This year I am looking forward to talks on: Java 9 Flow API; Angular 2; Microservices; lambdas; and many other topics. But, worryingly there does not seem to be a single talk with "Java EE" in the title. Like last year Devoxx Poland has attracted many great speakers.
Also, the food last year was delicious, so I hoping for the same this year.
Here is Devoxx 2015 video
Read : Devoxx Poland 2016
Java WSDL Import Without the .class Files
03 May 2016
It is easy to generate a SOAP client from a WSDL with Java. Java comes with the tool named 'wsimport'. The wsimport tool is part of the Java JDK, found in the JDK bin folder. By default when you run the tool it will create and keep the compiled .class files. If you do not need the .class files just add -Xnocompile
to the command.
wsimport http://localhost:8080/demo?wsdl -Xnocompile
Read : Java WSDL Import Without the .class Files