boztalay
boztalay

Reputation: 562

PowerMock and Android TypeNotPresentExceptionProxy When Mocking BluetoothDevice

My issue is that I'm trying to mock BluetoothDevice for some testing, but it's a final class. So, to mock it with PowerMock, I have to use the @PrepareForTest annotation. However, when I say @PrepareForTest({BluetoothDevice.class}), I get an exception. Here's the first few lines of the error output:

java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseArray(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(Unknown Source)

And here's the code that I'm using (the tests still need to be filled out, I was just reducing variables):

@RunWith(PowerMockRunner.class)
@PrepareForTest({ BluetoothDevice.class })
public class BluetoothCommTest {
    @Test
    public void testBluetoothComm() {
        fail("Not yet implemented");
    }
}

Thanks for the help!

Upvotes: 2

Views: 2529

Answers (1)

boztalay
boztalay

Reputation: 562

I figured out what was going on. I was following the instructions on this page, and the android.jar they provided was out of date, and didn't include the Bluetooth libraries.

To fix this, I used Powermock 1.2.5 and the android.jar that was included with the Android 15 SDK.

Upvotes: 1

Related Questions