Wednesday, August 23, 2017

Dockerizing a modern Java application


In this video I show the structure of a modern Java web application that uses Spring boot, Spring mvc, gradle, angularjs and then I will show how it is commonly prepared to run from within a docker container.




Full Source codes: https://github.com/SFRJ/tictactoe

Thursday, April 20, 2017

Browser automation in Java using Cucumber and Selenium


This is video I created to explain some of the very basics of browser automation in Java. Using the the classic tools Cucumber and Selenium.


Thursday, April 13, 2017

Implementing Strategy Design Pattern(Practical example)

In this video I show how to refactor some ugly if-else nested statements using polymorphism through the strategy design pattern.

Please note that I didn't use code coverage in this occasion, this was more of an Spike than a refactor I would say. My goal was to just show the implementation of the pattern and make a brief video. Of course if you are trying this in real software, please make sure that your code is covered by unit tests before proceeding.




Tuesday, April 11, 2017

Checking that 2 Lists have elements in common

How many times have we created loops to check if any of the elements of one list are contained among any of the elements of other list?

Lists have a contains() and also a containsAll() methods but they doesn't seem to do what we want and we end up writing spaghetti that looks like this often:

1:  boolean isSafeToEat(List<String> allergicFoods) {  
2:    for (String ingredient : getIngredients()) {  
3:      if (allergicFoods.contains(ingredient)) {  
4:        return false;  
5:      }  
6:    }  
7:    return true;  
8:  }  


Sometimes we forget that the Java API has so many useful things. Like this disjoint() method, from Collections.

1:    boolean isSafeToEat(List<String> allergicFoods) {  
2:      return Collections.disjoint(ingredients, allergicFoods);  
3:    }  

Its not Java 8 ;) its being there for a bit already, have a look at this docs:
https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#disjoint(java.util.Collection,%20java.util.Collection)

Refactor switch to Enum

Do switch statements sound good to you? 
Trust me better switch to Enum before it destroys your ears ;)



Monday, April 10, 2017

Mocking static method calls

Very simple example on how we can use method delegation to enable unit testing where there is a dependency to an static method call.



Friday, April 7, 2017

I love my new keyboard :)

Hello World! Look at my new keyboard:
comfortable, noisy, smells of bambu, spacious, feels dry and fresh all the time, nice polished surface finish, not hypersensitive to touch, resistant, doesn't need batteries, only relevant keys, free included mouse...  Using it for a week already, it works great. I just love it! :)))))))


Share with your friends