vijayjcp / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 2 forks source link

Mocking Enum sometimes work, sometimes not. It depends for Test invocation order. Throws ArrayIndexOutOfBoundsException #440

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Write some tests, mock Enum, write some tests
2. Or see Attachment and run Tests

What is the expected output? What do you see instead?
java.lang.ArrayIndexOutOfBoundsException: 2
    at com.blogspot.mstachniuk.powermockdemo.TaxCalculatorFactory.getInstance(TaxCalculatorFactory.java:6)
    at com.blogspot.mstachniuk.powermockdemo.TaxCalculatorFactoryTest.shouldThrowExceptionWhenUseNonExistCountry(TaxCalculatorFactoryTest.java:44)

What version of the product are you using? On what operating system?
PowerMock 1.5 with Mockito
Maven 2.2.1
JDK 1.6.0_41
Idea 12.1.1
Eclipse 4.2

Please provide any additional information below.
In TaxCalculatorFactoryTest are 2 Tests. I will mock Enum and this test 
sometimes work, sometimes not. When this test start as first, it works. When as 
2nd Test I get ArrayIndexOutOfBoundsException.
This error is in Maven, Eclipse and Idea reproducible.

Original issue reported on code.google.com by mstachniuk on 13 Apr 2013 at 2:33

Attachments:

GoogleCodeExporter commented 8 years ago
It works better when I use @PrepareForTest(Country.class) at Method level.

Original comment by mstachniuk on 22 May 2013 at 11:37