[Solved] Why Junit throws java.lang.ClassCastException even if classes are compatible and works fine in java code

Upcasting is always a codesmell and should be avoided. Usually it is needed because the code design violated the Tell, don’t ask! principle. Just guessing: In your case the “procution code” always passes instaces of class A so that it works. But your test obviously sets up a class B object (at some point you … Read more

[Solved] Best way to test a method that works with streams [closed]

Unittests in general test public observable behavior in your case it is the interaction with the two streams. create mocks for the two steams (usually I’d suggest to use a mocking framework but there are some simple implementations in the standard lib quite suitable for this purpose…) Configure the inputStream to return data in false … Read more