Thanks for quick response. I was missing @PrepareForTest for Util
class. I misunderstood the concept. I thought @PrepareForTest is
used for class which is being mocked so I had @PrepareForTest
({FileReader.class, BufferedReader.class})
Thanks again and you guys rock !!
On Jul 31, 2:20 am, Johan Haleby <
johan.hal...@gmail.com> wrote:
> Sorry, ignore the thing about "@Test(expected=FileNotFoundException.class)",
> I didn't read your code thoroughly enough. One more thing that you may have
> forgot is to run the test with the PowerMockRunner (i.e.
> @RunWith(PowerMockRunner.class)).
>
> /Johan
>
> On Fri, Jul 31, 2009 at 8:15 AM, Johan Haleby <
johan.hal...@gmail.com>wrote:
>
> > Hi,
>
> > Have you prepared Util.class for test using the @PrepareForTest annotation?
> > Also you don't need to expectNew for the BufferedReader class because an
> > exception would already have been throwed before. The test is also wrong
> > since you need to expect the exception as the outcome of your test, i.e. you
> > should declare you test-method with
> > @Test(expected=FileNotFoundException.class). You may also use replayAll()
> > and verifyAll() to make the test a bit simpler.
>
> > /Johan
>