Shaaf's blog

A technical blog about Java, Kubernetes and things that matter

Getting started with JBehave in 8 steps.

This post is about JBehave and how to quickly get started with it. If you would like to know about BDD please use the following link. What is Behavioral Driven Development? Today I have used JBehave for the first time. It does have some convincing factors for instance diving requirements into scenarios which map pretty nicely to the tests that are written with in the Steps. Thus it seems like it would be easier for Stakeholder/s to use it as a good guideline for the initial requirements.

Logging with log4J isDebugEnabled

Excerpt: Alot of times I have seen the questions popping up whether to use isDebugEnabled property or not. Arguably most of the times or rather always about performance. Some of the stuff that I feel important about using it follows. Alot of times I have seen the questions popping up whether to use isDebugEnabled property or not. Arguably most of the times or rather always about performance. Some of the stuff that I feel important about using it follows.

Command, Singleton, JMenuItem, JButton, AbstractButton - One Listener for the app

Here I would like to demonstrate a simple use of JMenuItems being used with Single Listener for the entire system. A simple sample of use would probably be SingleInstance Desktop Application. Lets see how that is done here. First lets create a OneListener class that should be able to listen to ActionEvents and also be able to add Commands to itself. Please refer to my previous post on Command,Singleton if you would like to see more about this patterns and there usage.

Doing the Locale - Danmark

The following illustrates how to get the Number format working with a danish locale. import java.text.NumberFormat; import java.util.Currency; import java.util.Locale; public class TestLocale { public static void main(String args[]){ // Create a Locale for Danmark Locale DANMARK = new Locale("da","DK"); // get the currency instance for this locale. Currency krone = Currency.getInstance(DANMARK); // Get a Number format for the locale. NumberFormat krFormat = NumberFormat.getCurrencyInstance(DANMARK); // A symbol for the currency String symbol = krFormat.

How to read a file from the JAR?

Someone just asked me this question today. And I thought might as well put it down for info. public TestReadFileFromJar() throws FileNotFoundException, IOException { InputStream is = getClass().getResource("txtData/states.properties"); read(is); } In the case above txtData is placed in the jar on the root. Remmember to add the path with the “/”