0

I'm trying to test a function by JUnit test.

public void create() {
    Locale locale = new Locale("en");
    persist(PersistAction.CREATE, ResourceBundle.getBundle("/bundle", locale).getString("UserCreated"));
    if (!JsfUtil.isValidationFailed()) {
        items = null;    // Invalidate list of items to trigger re-query.
    }
}

But I face this error when getBundle(). It's weird since it could get when Run project

Can't find bundle for base name /bundle, locale en
java.util.MissingResourceException
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1387)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:845)
    ...

I have already added these bundles in src/test/resources, which copied from src/main/resources:

  • bundle_en.properties

  • bundle_ja.properties

Please look at this image for structure https://gyazo.com/297091ef4120a6161bef31c9ead761ef

Trung NT Nguyen
  • 403
  • 2
  • 14
  • where are your .proprieties files ? – Ahmed Gamal Apr 18 '16 at 08:29
  • possible duplicates with :http://stackoverflow.com/questions/3727149/cant-load-resourcebundle-during-junit-test and http://stackoverflow.com/questions/10816737/java-unit-test-cant-access-resourcebundle – Ahmed Gamal Apr 18 '16 at 08:31
  • @Ahmed Gamal: Sorry I fotgot to specific the path of properties. It's src/test/resources ( I copied from src/main/resources) – Trung NT Nguyen Apr 18 '16 at 08:37

0 Answers0