@Test public void shouldGetRequestScopedMessageServiceInstance() throws Exception { ExposedMessageSourceImpl exposedMessageService = mock(ExposedMessageSourceImpl.class); whenNew(ExposedMessageSourceImpl.class).withNoArguments().thenReturn(exposedMessageService); MessageService messageServiceRequestInstance = mock(MessageService.class); whenNew(MessageService.class).withArguments(exposedMessageService, "en").thenReturn(messageServiceRequestInstance); MessageService requestInstanceMessageService = MessageService.getRequestInstance(); verifyNew(ExposedMessageSourceImpl.class).withNoArguments(); verify(exposedMessageService).setBasename("messages"); verifyNew(MessageService.class).withArguments(exposedMessageService, "en"); assertThat(requestInstanceMessageService, is(messageServiceRequestInstance)); }
@Scope(SCOPE_REQUEST) public static MessageService getRequestInstance() { ExposedMessageSourceImpl exposedMessageSource = new ExposedMessageSourceImpl(); exposedMessageSource.setBasename("messages"); return new MessageService(exposedMessageSource, "en"); }
MessageService { @Scope(SCOPE_REQUEST) public static MessageService getRequestInstance() { ExposedMessageSourceImpl exposedMessageSource = new ExposedMessageSourceImpl(); exposedMessageSource.setBasename("messages"); return new MessageService(exposedMessageSource, "en"); } }
MessageService { @Scope(SCOPE_REQUEST) public static MessageService getRequestInstance() { ExposedMessageSourceImpl exposedMessageSource = new ExposedMessageSourceImpl(); exposedMessageSource.setBasename("messages"); return new MessageService(exposedMessageSource, "en"); } @Autowired  MessageService(ExposedMessageSource messageSource, @Value("${locales.supported}") String locales); }
MessageService { @Scope(SCOPE_REQUEST) public static MessageService getRequestInstance() { ExposedMessageSourceImpl exposedMessageSource = new ExposedMessageSourceImpl(); exposedMessageSource.setBasename("messages"); return new MessageService(exposedMessageSource, "en"); } @Autowired  MessageService(ExposedMessageSource messageSource, @Value("${locales.supported}") String locales); @Scope(SCOPE_REQUEST) static MessageService getRequestInstance(); String message(String key); String message(OpenLmisMessage openLmisMessage); @SuppressWarnings("non-varargs") String message(String key, Object... args); Set<String> getLocales(); Map<String, String> allMessages(); Map<String, String> allMessages(Locale locale); }
MessageService { @Scope(SCOPE_REQUEST) public static MessageService getRequestInstance() { ExposedMessageSourceImpl exposedMessageSource = new ExposedMessageSourceImpl(); exposedMessageSource.setBasename("messages"); return new MessageService(exposedMessageSource, "en"); } @Autowired  MessageService(ExposedMessageSource messageSource, @Value("${locales.supported}") String locales); @Scope(SCOPE_REQUEST) static MessageService getRequestInstance(); String message(String key); String message(OpenLmisMessage openLmisMessage); @SuppressWarnings("non-varargs") String message(String key, Object... args); Set<String> getLocales(); Map<String, String> allMessages(); Map<String, String> allMessages(Locale locale);  }