I will very much appreciate if I get any answer regarding my problem with static method test which holds try-with-resources part of code.
Static method:
<pre>
public class PropertiesUtil {
public static Properties getProperties() {
Properties p = new Properties();
File configFile = new File("fileName");
<b>try (FileReader pFile = new FileReader(configFile)) {</b>
p.load(pFile);
} catch (IOException e) {
e.printStackTrace();
}
return p;
}
}
And when I run my test, run-with-resources block makes testing impossible:
<pre>
@Test public void testStatic() {
PowerMockito.mockStatic(PropertiesUtil.class);
PowerMockito.when(PropertiesUtil.getProperties()).thenReturn(new Properties());
... } I get failure trace:
java.lang.VerifyError: Inconsistent stackmap frames at branch target 663 Exception Details: Location: PropertiesUtil.getProperties()Ljava/util/Properties; @663: aload Reason: Type 'java/lang/Throwable' (current frame, locals[8]) is not assignable to 'java/lang/Class' (stack map, locals[8]) Current Frame: bci: @653 flags: { } locals: { 'java/util/Properties', top, 'java/lang/Throwable', 'java/lang/Throwable', top, 'java/lang/Throwable', 'java/lang/Throwable', top, 'java/lang/Throwable' } stack: { } Stackmap Frame: bci: @663 flags: { } locals: { 'java/util/Properties', top, 'java/lang/Throwable', top, top, 'java/lang/Throwable', 'java/lang/Throwable', top, 'java/lang/Class' } stack: { } Bytecode: 0000000: 123d b800 4312 4403 bd00 0312 46b8 004a 0000010: 124c b800 524b 2a01 3a05 013a 0619 0512 0000020: 59b8 005b 125c 125d b800 60b8 0064 3a07 0000030: 1907 b200 56a6 000b b200 563a 06a7 000a 0000040: 1907 c000 653a 0619 06a5 0008 2ac0 0057 0000050: b000 0000 0001 3a05 013a 0612 66b8 0060 0000060: 03bd 0003 1267 b800 68b8 006c 3a07 1907 0000070: b200 56a5 0032 1907 c100 6e99 0020 b800 0000080: 7412 75b8 0060 1203 01b6 007b b600 7f01 ...
How can I test this with PowerMockito??? Thank you in advance!
Aucun commentaire:
Enregistrer un commentaire