Posts

Showing posts with the label Java Development

Testing Lombok-based Classes in Java

Testing Lombok-based Classes in Java Lombok simplifies Java by auto-generating boilerplate like getters, setters, and constructors. But how do you **test** classes that use Lombok annotations? Here's a practical guide to unit testing Lombok-powered classes — and when you might want to go beyond relying on Lombok alone. ✅ Lombok Class Example Let’s use this simple class as our example: import lombok.Data; @Data public class User { private String name; private int age; } Lombok generates getName() , setName() , getAge() , setAge() , equals() , hashCode() , and toString() . 🔍 Should You Test Getters and Setters? Generally, you don’t need to test Lombok-generated methods like getters and setters — they’re stable and widely trusted. However, you might want to test: Custom logic added manually Builder pattern usage Correct field population Equality and immutability (e.g., for valu...

Java 11 Features: What Every Developer Should Know

Java 11 Features: What Every Developer Should Know Java 11, released in September 2018, marked the second Long-Term Support (LTS) version after Java 8. It brought several key improvements and changes that every Java developer should be aware of. Whether you're upgrading from Java 8 or just curious, here’s a rundown of the most impactful features. 1. var in Lambda Parameters Java 11 allows the use of var in lambda expressions: (list) -> list.size() // Old (var list) -> list.size() // Java 11 This is particularly useful when annotations are required: (@Nonnull var item) -> System.out.println(item); 2. HTTP Client (Standard) Java 11 standardized the HTTP Client API introduced in Java 9. It supports HTTP/1.1 and HTTP/2 and replaces the older HttpURLConnection . HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://...