Thursday, February 14, 2013

Want lambdas with jdk6? Here's an IDEA

All Java people are looking forward to jdk8 to bring more functional-like syntax to the language, but it will take some time before we'll really be able to code like that day to day. It may take years, before jdk8 gets fully adopted as a standard (how many of you already use jdk7 in production these days?) Till then, we'll still have to write all the verbose code around -- if you want to stick with Java language, of course.

Want to try how it will look like in your code today? Get IntelliJ IDEA 12. This is how my source code looks in it (Java 1.6.0_38-b05):


When I hover the grayed code, real syntax comes up:


Pretty cool, huh?

Extremely improves readability, when your anonymous class method's body is just one line return statement. And that's pretty often, when you're e.g. mocking method calls in unit tests.

Tuesday, February 12, 2013

SmartGit/Hg 4 and Docky in Ubuntu 12.10

Since the first time I started to use Ubuntu as a primary operating system on my work laptop, I liked the possibility of endless customization possibilities I could make in the OS to have the UI match my preferences. Although I trust UX engineers from Canonical to do the work for me in most cases, sometimes you like to use few things differently or simply try new cool widget in your day to day work.

One major customization that I've started to use is dock at the bottom or the screen. It keeps my most-used applications and aggregates their windows (when they are running). This functionality is of course inspired by great dock present in OS X systems.

I've used AWN in previous versions of Ubuntu, quite happily except few quirks, but in my newest 12.10 release, I've switched to Docky. I came across it on some Internet forum where I was looking for solutions to my issues with AWN in freshly installed system.

Docky bar at the bottom of the screen

Tuesday, February 5, 2013

Creating unit tests in core Liferay sources

Liferay has been catching up lately on the tests coverage. Many improvements have been made in the trunk located in liferay-portal / master branch on GitHub and since I've been fixing some things recently, I've included unit test for the changed class as well.

Quick start how-to:
  1. read Liferay testing documentation to get the basic picture,
  2. create your unit test in portal-impl/test/unit/.../<your_class>Test.java,
  3. create test methods as usual with JUnit 4.x,
  4. run the test and see results:
    • cd portal-impl,
    • ant test-class -Dclass=CustomJspRegistryImplTest,
    • note that only the name of the class is used, not the full name including package.
Testing just a single class at a time seems to be necessary, executing ant test-unit to run all existing unit tests seems to be time consuming (from minutes to tens of minutes).