'PowerMockito MissingResourceException ResourceBundle

im trying to test a method using
PowerMockito, this method calls ResourceBundle. this is the code of my class :

public class ClasstTotest{

    public String methodToTest(final String lang) throws IOException {
        
        final ResourceBundle i18n = ApplicationResource.getMessageBundle(lang);
        
        System.out.println(i18n.getString("mytextKey")); // the exception starts from this line
        
        // code....
        
        //return ...
    }
}

and this is my test class:

    @RunWith(PowerMockRunner.class)
    @PrepareForTest({ ApplicationResource.class})
    @PowerMockIgnore({ "javax.management.*" })
    public class ClasstTotestTest {
    
        @Before
        public void setUpMock() {
            
            PowerMockito.mockStatic(ApplicationResource.class);
        }
        
        @Test
        public void methodToTest_TEST() throws Exception {
            
            ClasstTotest classtTotestSpy = PowerMockito.spy(new ClasstTotest());
            final ResourceBundle resourceBundleMock = PowerMockito.mock(ResourceBundle.class);
            
            PowerMockito.when(ApplicationResource.getMessageBundle(any(String.class))).thenReturn(resourceBundleMock);
            
            PowerMockito.when(resourceBundleMock.getString("mytextKey")).thenReturn("my value");
            
            String result= classtTotestSpy.methodToTest("fr-FR");
// assertion...
    
        }
    }

but when i run my test i got the following error :

java.util.MissingResourceException: Can't find resource for bundle org.mockito.codegen.ResourceBundle$MockitoMock$1094973450, key mytextKey
    at java.util.ResourceBundle.getObject(ResourceBundle.java:450)
    at java.util.ResourceBundle.getString(ResourceBundle.java:407)

do you have in idea please what's the wrong with my test and why im getting "Can't find resource for bundle" error.

thanks in advance.

regards



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source