Monday, December 16, 2013

Review of the Instant Mock Testing with PowerMock

Hi!

Quite recently I was asked by Packt publishing to write a review of the book Instant Mock Testing with PowerMock by Deep Shah. I have just managed to go through it and would like to share my thoughts :)

Thursday, December 12, 2013

Spring's @Primary annotation in action


Spring is a framework that never stops to amaze me. It's because of the fact that it offers plenty of different solutions that allow us, developers, to complete our tasks without writing millions of lines of code. Instead we are able to do the same in a much more readable, standardized manner. In this post I will try to describe one of its features that most likely is well known to all of you but in my opinion its importance is undervalued. The feature that I'll be talking about is the @Primary annotation.

Monday, September 30, 2013

Review of the Getting Started with Guava book

Hi!

I didn't have much time to write posts recently (beacuse of work and my book "Mockito Instant") but I came across Bill Bejeck's book entitled "Getting Started with Guava". After having read it I decided that I will try also to blog about computer science related books. So without any futher ado let's move to the review :)

Wednesday, August 28, 2013

Mockito Instant - my book has finally been published!

I am very pleased to announce that my book about Mockito entitled "Mockito Instant" has finally been published! You can buy it at Packt Publishing online shop.

Friday, August 9, 2013

Injecting Test Doubles in Spring using Mockito and BeanPostProcessors


I'm pretty sure that if you have ever used Spring and are familliar with unit testing, you have encountered a problem related to injecting mocks / spies (Test Doubles) in the Spring's application context which you wouldn't want to modify. This article presents an approach how to solve this issue using Spring's components.

Tuesday, August 6, 2013

Spock - return nested spies / mocks


Hi! Some time ago I have written an article about Mockito and using RETURNS_DEEP_STUBS when working with JAXB. Quite recently we have faced a similliar issue with deeply nesetd JAXB and the awesome testing framework written in Groovy called Spock. Natively Spock does not support creating deep stubs or spies so we needed to create a workaround for it and this article will show you how to do it.

Wednesday, June 12, 2013

Mockito - Extra Interfaces with annotations and static methods


In the code I have quite recently came across a really bad piece of code that based on class casting in terms of performing some actions on objects. Of course the code needed to be refactored but sometimes you can't do it / or don't want to do it (and it should be understandable) if first you don't have unit tests of that functionality. In the following post I will show how to test such code, how to refactor it and in fact what I think about such code ;)

Saturday, June 8, 2013

Mockito - RETURNS_DEEP_STUBS for JAXB


Sorry for not having written for some time but I was busy with writing the JBoss Drools Refcard for DZone and I am in the middle of writing a book about Mockito so I don't have too much time left for blogging...

Anyway quite recently on my current project I had an interesting situation regarding unit testing with Mockito and JAXB structures. We have very deeply nested JAXB structures generated from schemas that are provided for us which means that we can't change it in anyway.

Saturday, March 30, 2013

Execution of Groovy scripts from Java - XmlSlurper and MarkupBuilder in mapping issues


Problem with mappings


In our project we came across a really big problem related to mapping. Having two systems that initially were defined by the BA to be somehwat simillar we have chosen the simple XSLT (done through Altova Mapforce) of the input message to the output one.

Afterwards it turned out that the functions required to perform a mapping are becoming enormous. An example of such a mapping is:
From the input message take a list of Cars iterate over it and find a Car whose field "prodcutionDate" is the lowest and the attribute "make" is equal to "Honda" and as the output return the "saleDate"
So in order to map it we decided to move to JBoss Drools. The decision tables were out of question since the logic was to complex and customized to be placed in the spreadsheet so we coded everything in the DRL files. Soon the rules got really big and some of our developers were forced to spend plenty of time on constant recreation of rules stated by the BA.

Out of frustration and after having seen all the amazing things at the 33rd degree conference I decided to start finding solutions to my problems which were:

Sunday, February 3, 2013

Drools decision tables with Camel and Spring



Hi!

As I've shown it in my previous post JBoss Drools are a very useful rules engine. The only problem is that creating the rules in the Rule language might be pretty complicated for a non-technical person. That's why one can provide an easy way for creating business rules - decision tables created in a spreadsheet!

In the following example I will show you a really complicated business rule example converted to a decision table in a spreadsheet. As a backend we will have Drools, Camel and Spring.


Tuesday, January 15, 2013

Drools integration with Spring vs manual rules creation



Hi!

 Often in your work you can come across with issues related to business logic. Let us assume that you have dozens of rules (for the time being in our project we have more than 50 and I used to work on a project where we had hundreds of those rules) that you have to implement, divide into some classes, subclasses, abstractions and of course unit test. This can be difficult and timeconsuming to both write and support. There are many ways of dealing with this problem and I will show you one of them - JBoss Drools.

Drools is a library specifically created for such purposes like implementing rules. As presented in Wikipedia:
"Drools is a rule engine implementaion based on Charles Forgy's Rete Algorithm tailored for the Java language." 
It contains a rule engine that can process rules wirtten using the Drools language (you can also provide rules in Excel spreadsheets! - perfect for Business side to support and maintain).

In the following example we will take a look at the way one can integrate JBoss Drools with Spring and an example of solving a similar problem without Drools.


Monday, January 7, 2013

Very interesting article about XSD

A friend from my project (that will soon start his own blog ;) here is his blog ) has found a very interesting article about XSDs and namespaces.

 Tutorial about XSD and namespaces

Thursday, January 3, 2013

Hamcrest Matchers, Guava Predicate and Builder design pattern



Hi coding addicts :)

Often, while coding we have to deal with some POJO objects that have dozens of fields in them. Many times we initialize those classes through a constructor having dozens of arguments which is terrible in any possibly imaginable way :) Apart from that the functions that use those constructors are hardly testable. Let's take a closer look at using a Builder to change that situation, together with Hamcrest matchers and Guava Predicates to unit test it.

Let's start off with taking a look at the POJO class.