MessageToClientManager { void injectSession(Class<?>[] parameterTypes, List<Object> arguments, T session) { if (parameterTypes != null) { int i = 0; for (Class<?> parameterType : parameterTypes) { if (parameterType.isInstance(session)) { arguments.set(i, session); break; } i++; } } }  abstract Map<String, Object> getSessionBeans(T session); MessageToClient createMessageToClient(MessageFromClient message, T session);  }
@Test public void injectSessionTest() { System.out.println("injectSession"); Class<?>[] parameterTypes0 = new Class<?>[] {}; Class<?>[] parameterTypes1 = new Class<?>[] {String.class}; Class<?>[] parameterTypes2 = new Class<?>[] {String.class, Session.class}; Class<?>[] parameterTypes3 = new Class<?>[] {HttpSession.class, String.class}; List<Object> arguments = Arrays.asList(null, null); Object session = mock(Session.class); HttpSession httpSession = mock(HttpSession.class); instance.injectSession(null, arguments, null); assertThat(arguments.get(0)).isNull(); assertThat(arguments.get(1)).isNull(); arguments = Arrays.asList(null, null); instance.injectSession(parameterTypes0, arguments, session); assertThat(arguments.get(0)).isNull(); assertThat(arguments.get(1)).isNull(); arguments = Arrays.asList(null, null); instance.injectSession(parameterTypes0, arguments, httpSession); assertThat(arguments.get(0)).isNull(); assertThat(arguments.get(1)).isNull(); arguments = Arrays.asList(null, null); instance.injectSession(parameterTypes1, arguments, session); assertThat(arguments.get(0)).isNull(); assertThat(arguments.get(1)).isNull(); arguments = Arrays.asList(null, null); instance.injectSession(parameterTypes1, arguments, httpSession); assertThat(arguments.get(0)).isNull(); assertThat(arguments.get(1)).isNull(); arguments = Arrays.asList(null, null); instance.injectSession(parameterTypes2, arguments, session); assertThat(arguments.get(0)).isNull(); assertThat(arguments.get(1)).isEqualTo(session); arguments = Arrays.asList(null, null); instance.injectSession(parameterTypes2, arguments, httpSession); assertThat(arguments.get(0)).isNull(); assertThat(arguments.get(1)).isNull(); arguments = Arrays.asList(null, null); instance.injectSession(parameterTypes3, arguments, session); assertThat(arguments.get(0)).isNull(); assertThat(arguments.get(1)).isNull(); arguments = Arrays.asList(null, null); instance.injectSession(parameterTypes3, arguments, httpSession); assertThat(arguments.get(0)).isEqualTo(httpSession); assertThat(arguments.get(1)).isNull(); }