How do you mock a Sealed class?

Brett Veenstra picture Brett Veenstra · Aug 9, 2008 · Viewed 37.3k times · Source

Mocking sealed classes can be quite a pain. I currently favor an Adapter pattern to handle this, but something about just keeps feels weird.

So, What is the best way you mock sealed classes?

Java answers are more than welcome. In fact, I would anticipate that the Java community has been dealing with this longer and has a great deal to offer.

But here are some of the .NET opinions:

Answer

Haacked picture Haacked · Aug 28, 2008

For .NET, you could use something like TypeMock, which uses the profiling API and allows you to hook into calls to nearly anything.