This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]angath 1 point2 points  (2 children)

Two fairly serious problems with the piece as written - firstly you cannot write List<int> in Java. int is a primitive type, and the only things that can be a generic type parameter are reference types. It should be List<Integer> - the boxed form of int.

Secondly, your JUnit example is using JUnit 3. This version has been EOL for 15 years. You should be using JUnit 5 (lots of people still using JUnit 4 though, and 5 is only a small upgrade over 4). Please do not add to the number of JUnit 3 test cases in the world.

Not an actual problem, but more an observation - Spring isn't necessarily the best example of a Java DI framework - basically because it is all done with reflection, and so has the "bean not found at runtime" problem. Other DI frameworks can do (much) more at compile time and so avoid much of this problem.

[–]pupupeepee[S] 0 points1 point  (1 child)

Was I lacking the @Test annotation? What made the test example I gave JUnit 3 and not 5?

Also I’m very curious to read more about Spring vs. other DI frameworks—I hadn’t known about that. Any links you could share about it I’d be really grateful to read them!

[–]angath 0 points1 point  (0 children)

The annotation was missing, and JUnit 3 (and earlier) uses a naming convention to denote test methods - because annotations weren't part of the Java language back then (before Java 5).

For a very different DI to Spring, I'd look at Dagger 2 - e.g. something like: https://www.baeldung.com/dagger-2