Group JUnit Tests with @Nested

I really like the way that I can nest my JavaScript tests using describe blocks. This keeps my tests nicely organized and grouped together in functional blocks which can be super useful when you get a whole lot of tests created. describe("my component", () => { describe("validation", () => { it("ensures that user name is provided", () => { // test here }) it("ensures that password is valid", () => { // test here }) }) describe("when saved", () => { it("displays an indication that mutation is in progress", () => { // test here }) it("provides feedback of success", () => { // test here }) it("provides an error message on failure", () => { // test here }) }) }) I was not aware that you can do something like this in Java with JUnit. Reading through Pragmatic Unit Testing in Java with JUnit I found that this functionality is available by making an inner class and using the @Nested annotation. ...

February 14, 2025 · 2 min · Jamal Hansen

You don't need a 'B' suffix for byte literals in Java

Today I was coding in Java and I came across a part of the code where I was using a byte literal. I’ve been using Java for a while, so I knew that you have to suffix long literals with an ‘L’ otherwise Java complains. long myLong = 3000000000L; // Java is happy long myOtherLong = 3000000000; // Java is sad (too big for int) So when I went to create my byte literal I figured I would need to put a suffix on the number, like I do with long literals. But when I tried it, it turns out I didn’t need to. ...

February 7, 2025 · 2 min · Jamal Hansen