Archive

Archive for the ‘Java’ Category

VI like editing in eclipse

August 25th, 2010
Adrian Elsener

Since a few days I’m using a plugin in eclipse which allows vi like editing. It’s called vrapper and can be found under http://vrapper.sourceforge.net. It is a very good light weight alternative to commercial vi plugins. In my opinion there are not more disadvantages as in other vi plugins.
Sometimes it has hangers, this means it does not fall back to the main state instead it hangs in any command mode. In this rare cases normally helps to restart the plugin with the icon in eclipse.
The installation is very simple, only add the stable update site (http://vrapper.sourceforge.net/update-site/stable). Or if not possible to use the update site just download the file from http://sourceforge.net/projects/vrapper/files/, just copy the files into the plugins directory ;) .

If you like to use vi commands look in and check it out.

 

Java , , , ,

Mockito – Answer vs. Return

July 20th, 2010
Adrian Elsener

Did you had the problem your mock must act like a bean? And you could not create the object with the real implementation? And the interface was too large, so you would not create a innerclass for the test? I had this problem too. I solved it with the answer in mockito.

read more

 

Java, Test Driven Development, Testing , , , , , ,

Create mocks with mockito

June 25th, 2010
Adrian Elsener

This is a small summarization what the differences are between the different variations creating mocks with mockito.

Null values (default)

Per default, after creating a mock, every method will return null. Just create your mock with:

Sample sample = Mockito.mock(ISample.class);

I think, this is very useful and straight forward. (And based by mockito developers idea, to create very fast a mock for testing). Sometimes it is very difficult to determine an error which was produced through such a null value. For this case it is very practicable to tell mockito, returning SmartNullValues.

read more

 

Agile, Java, Test Driven Development, Testing , , , , ,

How to find a concurrency bug with java?

August 25th, 2009
Daniel Schröter

How to find a concurrency bug – this was the question I asked myself some time ago.
It is always very hard to find a concurrency bug. Mostly you have no idea when it happens or if it is really a concurrency issue or some nasty bit of code. If it is a concurrency issue the question is if the bug is in your code or in a supplied library? Will the problem happen only on multicore processors or on any machine? Besides the technical problem the customer is eager to get a solution and management… we’ll i guess you know the story.
I won’t be able to tell you everything there is to know about concurrency testing – but I’ll show you a way that worked for me in most cases.
read more

 

Java, Methodology, Testing , , , ,

Strange Java 1.6.0 update 14 debugging problem

June 26th, 2009
Adrian Elsener

A few days ago, we upgraded the jdk we use for development. After this some developers experienced a special problem with our eclipse while debugging. When they set a breakpoint, eclipse did not stop. After a try and error phase we found a working solution. The problem disappeared when we set the vm parameter -Xms (define initial size of heap) to a higher value for the jvm inside eclipse. In our case we set -Xms to -Xms256m. We still do not know why this solution works. But we thought we’ll let you know.

 

Java, Software , , , ,

Luke – The Lucene Index Toolbox

June 13th, 2009
stefan.jaeger

Lucene offers great full text search capabilities. It is based on an index, which is maintained by Lucene. With Luke, the Lucene Index Toolbox (http://www.getopt.org/luke/) you can analyze your index and let explain queries.

After startup, you have to select your index. For this example, I created a test index with one file. It’s content is “this is a lucene test”. I used the StandardAnalyzer, which uses the WhitespaceTokenizer and filters out all tokens less than 3 characters and stop words. This will result in an index of the terms “lucene” and “test”.

image 

read more

 

Java ,

Perform XPath Queries inside Ant

May 17th, 2009
stefan.jaeger

Ant offers some XML features like the xslt task, which transforms XML files into other files. But unfortunately, with Ant you can’t make simple XPath Queries on a specific XML file.

 

Luckily, there is a nice open source solution called XmlTask, which offers many possibilities to work with XML files.

 

  1. Download the latest version of XmlTask from http://xmltask.sf.net
  2. read more

 

Java , ,

GC Viewer

May 15th, 2009
stefan.jaeger

Wrong use of the memory options can cause serious performance problems. To optimize the right memory size of the JVM or to find some critical memory issues, the GC log of the JVM can be very useful. Simply start the Java application with the option -Xloggc:<file>. Every GC action gets logged into this file.

To analyse this log file, there is a nice tool called GCViewer, which can be downloaded from http://www.tagtraum.com/gcviewer-download.html. GCViewer is able to display the memory usage of the application based on time and old/young generation heap space.

clip_image002

read more

 

Java ,

Use Groovy inside Ant

May 13th, 2009
stefan.jaeger

There are some kind of tasks, which Ant won’t do. One of them is the loop. There is no simple way to implement a dynamic for or while loop in Ant. What do i mean with dynamic? Let me make an example. Ant reads out a number of iterations from a property file (we call it the number x) and should perform a loop x-times to call another Ant task. And this can only hardly be done with Ant.

Groovy But fortunately, there is Groovy. Groovy is a scripting language, which runs in a Java Virtual Machine. And because of that, it can be easily integrated with Ant.

read more

 

Java , ,

Mockito

April 6th, 2009
Adrian Elsener

A few weeks ago, I started using Mockito. Mockito is a mocking framework for Java.

What mockito is able to do:
- mocking interfaces and abstract classes
- mocking concrete classes
- spy real objects

(http://code.google.com/p/mockito)

I liked mockito so much that I decided to present it to you…
read more

 

Java, Testing , , ,