I reproduced this problem locally and this exception ...
org.springframework.web.util.NestedServletException: request processing failed; Nested exception - java.lang.IllegalArgumentException: null source
... strong implies that the constructor of your VehicleAddedEvent looks like this:
public VehicleAddedEvent(Vehicle vehicle) { super(null); }
If you look further on the stack, you are likely to see something like this:
Caused by: java.lang.IllegalArgumentException: null source at java.util.EventObject.<init>(EventObject.java:56) at org.springframework.context.ApplicationEvent.<init>(ApplicationEvent.java:42)
So, in response to your question; the problem is not with your test, but with a super call in the VehicleAddedEvent constructor, and if you update this, that is, calls to super(vehicle) rather than super(null) , posting events will not raise an exception.
This will allow you to complete your test, although there is nothing in your test that claims or verifies that this event was posted, so you might want to learn something for this. You probably already have an implementation of ApplicationListener<Vehicle> (if not, I'm not sure what the benefit of posting a โvehicle eventโ is, so that you can @Autowire insert VehicleControllerTest and make sure that the vehicle event has been posted as possible :
source share