Which is the better way to write junit?
className object = new className("test");
when(className.someMethod()).thenReturn(object);
OR
when(className.someMethod()).thenReturn(new className());
Both are fine and depend on your use case. With the first approach you still have direct access to the return value.
If you don't need it (e.g. in your assert statement), then the second approach is fine as well.
Simple Java rules. Nothing special.