Andrew Albert's weBlog

A minimal jbehave maven project

I’m dipping my toes in BDD and learning the jbehave framework. I found it surprisingly difficult to find a simple, self-contained example to use as a starting point. I wanted a maven project that depended only on junit and jbehave.

Here’s my minimal jbehave maven project; I hope it helps someone else get up and running quickly. Thanks to David Daedalus and Andreas Ebbert-Karroum, whose code I borrowed, trimmed, and mashed together.

Project Directory Structure

You need 4 files: pom.xml, AnnotatedSteps.java, RunJBehaveStoriesAsAJUnitTest.java, and Math.story in the following directories:

src/test/java/...package.../AnnotatedSteps.java
src/test/java/...package.../RunJBehaveStoriesAsAJUnitTest.java
src/test/resources/Math.story
src/pom.xml

The filename Math.story is only significant in that RunJBehaveStoriesAsAJUnitTest’s storyPaths method specifically looks for it. You could instead match patterns (like David Daedalus does) using one of StoryFinder’s findPaths methods.

Source code

Edit: I didn’t love the way the source was formatted here. Instead, I’ve created a repo over at bitbucket to house it.

The most interesting part is the scenario told in Math.story, an example written in the “given…when…then…” structure:

Scenario: 1 + 1 = 2
Given a variable x with value 1
When I add 1 to x
Then x should be equal to 2

This is what appeals to me about BDD: examples drive feature development. These examples later serve as automated regression tests. You’re also creating living technical documentation with these examples; it’s never out of date because it’s executable.

Running

run on the command line with mvn clean test

...snip...

(BeforeStories)

Running story Math.story

(Math.story)
Scenario: 1 + 1 = 2
Given a variable x with value 1
When I add 1 to x
Then x should be equal to 2



(AfterStories)

...snip...

Updating to Java 8

Java 8 was released earlier this week, so I downloaded and installed JDK 8 & NetBeans 8.0. After updating my PATH environment variable, I was surprised that powershell was still finding an old Java version:

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Users\andrew> java -version
  java version "1.7.0_51"
  Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
  Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)

but cmd.exe was finding the java.exe I was expecting…

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\andrew>java -version
  java version "1.8.0"
  Java(TM) SE Runtime Environment (build 1.8.0-b132)
  Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

Confusing, right?

I vaguely remembered that the Java installer copies the java.exe runtime somewhere else and checked:

C:\Users\andrew>where java
  C:\Windows\System32\java.exe
  C:\Program Files\Java\jdk1.8.0\bin\java.exe
  C:\Program Files\Java\jre7\bin\java.exe

and also noticed that C:\Windows\system32 was in my path ahead of C:\Program Files\Java\jdk1.8.0\bin:

C:\Users\andrew>echo %path%
  ...;C:\Windows\system32;...;C:\Program Files\Java\jdk1.8.0\bin;...

Changing the order of these in my path fixed my issue in powershell:

PS C:\Users\andrew> java -version
java version "1.8.0"
  Java(TM) SE Runtime Environment (build 1.8.0-b132)
  Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

I assumed that the Java 7 installer I’d used copied java.exe into System32, but the JDK 8 & NetBeans 8.0 installer didn’t.

That doesn’t seem to be the case, and I’m still confused. Look at:

PS C:\Windows\System32> .\java.exe -version
  java version "1.7.0_51"
  Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
  Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)

compared with:

c:\Windows\System32>java.exe -version
  java version "1.8.0"
  Java(TM) SE Runtime Environment (build 1.8.0-b132)
  Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

Why does it seem like c:\Windows\System32\java.exe is different depending on if I’m in powershell or cmd.exe?

Use Markdown as the default syntax for editing tumblr posts

Maybe it’s me – am I the only one that finds tumblr’s UI awkward and unintuitive? (I actually had to use google to figure out how to rename my blog :|). Enabling markdown-syntax for your posts was another feature that I had to hunt to find:

  • From your dashboard (https://www.tumblr.com/dashboard)
  • Click the cog wheel at the top
  • With “Account” selected, there is an “Edit posts using” option. Select Markdown.

Not too well-hidden once you know where to look. Maybe it’s me.

While googling, I also found this news post from 5 years ago about markdown via email or mobile: if you include !m anywhere in the subject or body of a post, markdown syntax will be used. Neat.

Changing the sublime text 3 sidebar colors

I wish sublime’s themes affected its side bar. Because sublime shares the same .tmTheme themes as textmate, they don’t, but you can manually change the sidebar style by editing Default.sublime-theme.

To do this, edit the “sidebar_tree”, “sidebar_heading”, etc classes in Packages/Theme - Default/Default.sublime-theme. I overrode those defaults by putting this Default.sublime-theme inside the Packages/User folder. It recolors the sidebar to better complement my solarized(light)-themed editor. Here is a similar Default.sublime-theme for solarized(dark).

p.s. I always forget where my Packages folder lives. From the sublime text menu, selecting “Preferences → Browse Packages…” will take you to it.

Sublime’s “goto anything” (ctrl+P) in Netbeans…

The more I use sublime, the less I want to use any other editor for my code.

Fortunately, I found a netbeans plugin (open file fast) which can stand in for one of my favourite sublime features.

The 6.9 version still worked for NB 8.0. Thanks to mrtwice99 for these instructions:

  • Download the 6.9 .nbm
  • In NetBeans, go to Tools → Plugins → Downloaded → Add Plugins, select the downloaded file and click Install (http://wiki.netbeans.org/FaqPluginInstall)
  • Restart NetBeans (although it is not needed to run the plug-in, I found that I couldn’t set key short cut for Open File Fast)
  • Now for the short cut. Go to Tools → Options → Keymap, search for “open file fast” → Assign short cut

Update: The plugin is still working on the latest version of netbeans (8.0). Also, if like me you’re using Ctrl+P for the shortcut, you might want to reassign “Show Code Completion Tip Popup”. :-)