Skip to main content

Posts

Showing posts from June, 2015

“Best” practices – mindset matters

“Sir, can you please switch off your mobile phone or keep it in flight mode during the entire flight?” The flight attendant approached a young guy and told. The guy did not like what she said, looks like he was busy in a very important call and not in a mood to discontinue the conversation. But she did not give-up and thanks to the federal law, the guy had to hang the call and switch off his mobile. I often encounter such situation during flight, most of these occur either because of electronic devices or fastening of seat belt. These are very trivial matters but can generate greater negative impact during the flight. Let’s take the case of mobile phone or any electronic devices, these devices are equipped with Wi-Fi and may interfere with the cockpit devices causing communication breakdown. The modern flight operating devices are designed to block such interference; however it is highly recommended that the devices are switched off or kept in flight mode. There can b...

Spring: Method Injection

This is useful when a Singleton bean need to use a non-singleton bean. Sometime your application may need to collaborate a prototype bean with a singleton bean to satisfy your business logic. That is your singleton bean is dependent on a prototype bean. Let’s consider three beans Customer Sales Person Product A customer may ask a sales Person to show different type of products from the repository. Let’s assume you have gone to a garment shop to buy a new shirt for the lucky date with your new girlfriend. So, it’s a tough choice and you may like to try different colors and styles and finally you will choose one. So, if we describe the above situation in the form of business logic inside one of your module, it will look like this, The sales Person should show a new product every time he requests. Let’s assume Customer and Sales Person to be singleton bean in your Spring container and Product as prototype. But based on bean life-cycle a prototype bean can not be injec...

JUnit Rule : Creating Temporary Folder

I was surprised to see this beautiful feature in JUnit and it helped to ease to lots of constrains I face while writing JUnit tests. I basically follow TDD and as you guys know we focus more on writing tests, hence it is necessary to use some shortcuts availed by the tools like JUnit to make the process fast. Recently I had an issue where I had to create and delete a file before and after every test executes. I did that using @Before and @After annotation of Junit and it worked, however I was looking for more of a generic way to do this at one place. As I started googling I came across this post, which is amazing,  After reading the block I know how I can generalize my creating and deleting of a temporary file or folder (I decided to go with a temporary folder and a file inside it, which looks more readable and oganized). The JUnit class: public class TemporaryFolderTestCase { @Rule public TemporaryFolder temporaryFolder = new TemporaryF...