Don’t let Java varargs limit an API
Was looking at Simple Logging Facade for Java (SLF4J), a Java logging library. One nice feature is that one can use message formats that don’t get evaluated until the log statement is executed, which...
View ArticleRegex group capture with optional delimeter
Ever had one of those days where the simplest thing seems complex? A simple regex is doing that to me now. This is the example, simplified. You have a string “BEFOREAFTER”. If this string has a ‘x’ in...
View ArticleGroovy implementation of INIX file format, part 2
Continued experimentation with the INIX “ini” file format. I take the original post code and add an alias feature. Background In three prior posts I presented a very simple metadata file storage...
View ArticleGroovy Object Notation using ConfigSlurper
In an old post in 2010 I was exploring the idea of using Groovy syntax as a data interchange format, GrON, just as JSON is a “subset” of Javascript. Just noticed that Groovy has, since version 1.5, the...
View ArticleJava reflection on a message using MethodHandle
Some code I was looking at recently had an overloaded method and each method just accepted a different type argument. With Generics there are probably ways to reduce this clutter, or not. Anyway, I...
View ArticleGroovy is a language
A few years ago I wrote a few Groovy language scripts to help with some configuration and testing needs. I discussed these with my co-workers. But, lo and behold, for weeks they thought I was saying...
View ArticleRun svn command from Java using Commons exec
In a project I will need to marshal a Subversion log into Java. First step was getting Java to talk to a subversion repository. There are many options for doing this. Two of these are using a SVN API...
View ArticleUse JAXB to export Subversion log to Java
In a previous blog post I obtained the subversion XML log output. Now I need to convert that into Java objects in order to provide some special reporting requirements. Below I just present the...
View ArticleSvnKit E170001: Negotiate authentication failed: ‘No valid credentials provided’
In a new project, attempts to programmatically access our Subversion server using SvnKit fails with an E170001 error. But, only on one Windows 7 workstation. After a lot of searching on web for answers...
View Articlemaven-tomcat7-plugin not extracting the war file
The Apache Tomcat Maven Plugin has a great feature: it can create a runnable jar file with an embedded Tomcat server. I tried this on a simple ‘Hello world!’ webapp to see if this works. It didn’t....
View ArticleUnit testing Java exception handling using JMockIt
How do you test that a method caught an exception? What if that catch did not have a side effect, it just logged output, or simply swallowed the exception? Context We have a method in a class that was...
View ArticleSearch Java classpath for JUnit tests using Spring
A simple classpath scanner implementation that searches for classes having any method annotated with @Test or @RunWith. Spring Framework’s scanner utility is used to do this. Many tools and dev...
View ArticleHow to unit test Java servlets
The question of how to unit test Servlets comes up a lot. How can it be done? Should it be done? What are the options? A unit test, in the realm of xUnit semantics, is an isolated test of the smallest...
View ArticleJava fluent inline map initialization
This is a common task, and there are many good and bad solutions out there. Java 8 even has a “Supplier” that can assist with inline map initializations. Unfortunately, Java does not have a simple...
View ArticleJava dupe key Properties detect using Commons Configuration
Java Properties files can contain duplicate key entries. This can be a problem since the Java Properties loader will just keep the last value parsed. Not a problem for small applications, but when...
View ArticlePrune deleted folders of repo diff report using Java
Sometimes the contents of deleted folders are not relevant. Just showing the top level deleted folder or dir is enough. For example, in a branch diff against trunk, folder moves are shown as adds and...
View Article