The builder pattern is great, isn’t it? It lets you create nice immutable classes without the need for multiple constructors and it gives the API users freedom in choosing which arguments they want to use when creating the instance. But what happens when you want to tell the user that she must call one builder [...]
Entries Tagged 'Java' ↓
Builder pattern with a twist
February 7th, 2012 by Uzi Landsmann — Java, Tips & Tricks
Changing an index in MongoDB
December 15th, 2011 by Jan Kronquist — Java
We are using the @Indexed annotation in Morphia and when we changed to @Indexed(unique=true) we were first surprised when nothing happened. Our first thought was that this might be a problem in Morphia. However, on second thought automatically changing an existing index is probably not a good idea! Although I couldn’t find anything in the [...]
Spring Integration Tests, Part II, Using Mock Objects
December 12th, 2011 by Mattias Severson — Java, Testing
In the previous post, I wrote how you can use Spring’s FactoryBean to facilitate the creation of mock objects for Spring integration tests. Now, it is time to use the EasyMockFactoryBean (in this post EasyMock has been used for creating mock objects, but a similar approach applies to Mockito as well. Start by looking at [...]
Tags: easymock, mock, mockito, spring
Autowiring Morphia entities
December 7th, 2011 by Jan Kronquist — Java
My current project is using Morphia to handle object mapping to/from mongoDB and I wanted to add dependency injection using Spring to my entities like this: @Entity public class MyEntity { … @Autowired @Transient private SomeService someService; } Notice the @Transient annotation that tells Morphia to avoid persisting this field! I solved this problem by [...]
Tags: mongodb, morphia, spring
Spring Integration Tests, Part I, Creating Mock Objects
November 30th, 2011 by Mattias Severson — Java, Testing
When writing integration tests with Spring, it can sometimes be convenient to mock one or more of Spring bean dependencies. However, during some circumstances strange things may happen… (In this post, Mockito has been used for creating mock objects, but the same problem applies to EasyMock as well. You can find the corresponding files if [...]
Tags: easymock, factory-method, factorybean, mock, mockito, spring
Getting Started with Spring Data – MongoDB in Scala
October 24th, 2011 by Amir Moulavi — Java
I used MongoDB for a project in 2010 and I had great experience with it. Unfortunately I didn’t get the chance to work with this agile and scalable document-oriented database again until now. But my current assignment has brought the opportunity to use it in production In this post I want to show you a [...]
Tags: mongodb, scala, spring data, tutorial
Facebook Test Java API release 1.1.5
October 20th, 2011 by Tobias Södergren — Java, Testing
The Facebook Test Java API framework has been updated. There are two additions to the API and one bugfix: Bugfix for NPE when calling facebookStore.createTestUser(false,”…”). Added possibility of using a provided HttpClient instance in HttpClientFacebookTestUserStore. Added unit test that displays the use of json-path when asserting data. Here’s a quick reminder of how to create [...]
Tags: Facebook, framework, Java, open source, test
Experimenting with Scala Parallel Collections (contd.)
October 18th, 2011 by Amir Moulavi — Java
In the previous post we went through Scala parallel collections and you saw how you can convert a sequential collection into a parallel one by using method par on that collection. In this post I want to show you how you can write your own parallel collection in Scala. The example I use for this [...]
Tags: collection, parallel, scala
Getting started with Android NDK
October 13th, 2011 by Per-Erik Bergman — Android, Embedded, Java, Tips & Tricks
You want to try out the Android NDK? I have gotten a lot of questions about how to setup and work with the NDK and I decided to write down how I do it. My goal with this entry is to gather all the information you need to get started with the Android NDK. I [...]
Tags: Java, ndk, programming, tutorial
Injectors and Extractors in Scala
October 11th, 2011 by Amir Moulavi — Java
If you have used case classes in Scala, you can not neglect the power they bring to your applications. They provide a recursive decomposition mechanism via pattern matching. In this post I go through injectors and mostly extractors. You will see that how extractors can be employed for pattern matching. Consider that we need to [...]
Tags: case, extractor, injector, scala
Simple Parsing of Complex JSON and XML Documents in Java
October 9th, 2011 by Johan Haleby — Java, Testing, Tips & Tricks
In this blog I’m going to demonstrate how to parse and validate more complex JSON and XML documents in Java using the REST Assured framework and the XmlPath and JsonPath components available in this framework. Since REST Assured is implemented in Groovy it can be really beneficial to take advantage of Groovy’s collection API. Let’s [...]
Scala Type Variances – Part three
October 5th, 2011 by Amir Moulavi — Java
So far we have seen how to define covariant and contravariant subtypes in Scala. In this post we will study lower bounds and upper bounds and see how they can be of great help when designing your application. Lower bounds Consider the class I defined in the first post: Company is covariant in type T [...]
Tags: lower-bound, scala, subtyping, type, upper-bound, variance
Scala Type Variances – Part two
October 4th, 2011 by Amir Moulavi — Java
In the previous post, I went through what covariant subtyping is. In this post we will study contravariant subtyping with a small example. Contravariant Subtyping Do you remember the definition of covariant? Contravariant is the other way around. I will clarify this by the following example (example is adopted from [1]). Consider we have a [...]
Tags: contravariant, scala, subtyping, type, variance
Scala Type Variances – Part one
October 3rd, 2011 by Amir Moulavi — Java
I remember when I started to learn Scala, I usually come up with brackets in the Scala API doc that have plus and minus characters inside. Honestly that scared me a little bit! But after I learned a bit about Scala type system, I know the purpose of theses type declarations and I appreciate their [...]
Tags: covariant, scala, subtyping, type, variance
Experimenting with Scala Parallel Collections
October 2nd, 2011 by Amir Moulavi — Java
In this short post, I want to show you how you can avail from Scala parallel collections in your application and under which conditions it makes sense to use it. Parallel Collections were introduced in Scala 2.9 release which are built on the same abstractions and provide the same interfaces as existing collection implementation. It [...]
Tags: collection, parallel, scala
