r/java • • Dec 11 '25

Modern Bytecode Instrumentation with ByteBuddy – Rafael Winterhalter | The Marco Show

https://www.youtube.com/watch?v=AzfhxgkBL9s
40 Upvotes

12 comments sorted by

View all comments

Show parent comment

2

u/repeating_bears Dec 12 '25

That's right, but it would also be possible to mix and match.

Here's an example where Post provides a default for 'content', which the test factory method uses, but the factory method also applies more defaults on top of that.

class Post {
    Post(String title, List<String> tags, boolean isVisible, String content = "") {
        //...
    }
}

class MyTest {
    @Test
    public void something() {}
    
    private static Post createPost(
        String title = "Test Post",
        List<String> tags = List.of("news"),
        isVisible = true
    ) {
        // content is omitted, so Post's default is used
        // Perhaps the tests have no reason to change it
        return new Post(title, tags, isVisible);
    }
}