Anti Pattern: Don’t use Optionals for data repositories Java 8 Optionals Java 8 introduced a new feature call Optionals. Optionals are an easy way to force the caller of a method to deal with a possible null return value: 123456 public Optional<String> getName() { ...} Optional<String> name = getName();System.out.println(name.orElse("I forgot my name"); If you use an Optional as the return type of your method, whoever calls the method will be reminded that it might return […]
Create random test objects with Java reflection Although Java is an object oriented language, you will often separate our data and your actual business logic. You will write POJOs, entities, domain models and DTOs which you will pass to services, repositories and controllers. If you do so, you will properly need test data for those objects. Often, the data you pass will […]