Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. import java.util.Locale;
  2.  
  3. /**
  4. * Rule allows to use specific locale for particular tests.
  5. *
  6. * Default locale is stored before test and restored after.
  7. * Rule can be used on the method or class level.
  8. *
  9. * @author setkomac
  10. *
  11. */
  12. public class LocaleRule extends InitializationRule {
  13.  
  14. private static final Locale defaultLocale = Locale.getDefault();
  15. private Locale locale;
  16.  
  17. /**
  18. * Object constructor.
  19. * @param locale Local that will be used inside test.
  20. */
  21. public LocaleRule(Locale locale){
  22. this.locale = locale;
  23. }
  24.  
  25. @Override
  26. public void before() {
  27. Locale.setDefault(locale);
  28. }
  29.  
  30. @Override
  31. public void after() {
  32. Locale.setDefault(defaultLocale);
  33. }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement