Motivation: When I have my own SseEmitter and populate it with events, then I would like to write a unit test with TestHandler to assert events being sent

Comment From: bclozel

Thanks for raising this @kkocel !

What do you mean by "my own SseEmitter". Are you subclassing this type? Can you explain why?

Comment From: kkocel

@bclozel I don't subclass it; just create a new instance and initialize it with a custom TestHandler copied from SseEmitterTests.

Here is how I test:

val testHandler = TestHandler() // test handler copy & pasted from https://github.com/spring-projects/spring-framework/blob/main/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitterTests.java#L141
val emitter =
            SseEmitter().apply {
                initialize(testHandler)
            }

 MyClassThatEmitsEventsUsingEmitter(emmiter)

I need to put those tests in org.springframework.web.servlet.mvc.method.annotation package to make initialize and Handler visible.

Comment From: bclozel

Unless I'm missing something, you're testing SseEmitter itself - we don't intend to open up our API for this use case.

Comment From: kkocel

@bclozel Actually, no, I tested my class, and SSeEmitter is only a sink for generated events from my class.

Do you know any other way to extract those events from SSeEmitter?

Comment From: bclozel

In that case, I think introducing a test utility for SseEmitter would be a better idea. I don't think we should make such methods public as it will confuse developers and make methods available that have no use besides testing. I've created #33746 for that.