1
1
/*
2
- * Copyright 2002-2014 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -50,19 +50,18 @@ public class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
50
50
51
51
52
52
@ Before
53
- public void setup () throws Exception {
53
+ public void setup () {
54
+ super .setup ();
55
+
54
56
MockitoAnnotations .initMocks (this );
55
57
this .handshakeHandler = new DefaultHandshakeHandler (this .upgradeStrategy );
56
58
}
57
59
58
60
59
61
@ Test
60
- public void supportedSubProtocols () throws Exception {
61
-
62
+ public void supportedSubProtocols () {
62
63
this .handshakeHandler .setSupportedProtocols ("stomp" , "mqtt" );
63
-
64
64
given (this .upgradeStrategy .getSupportedVersions ()).willReturn (new String [] {"13" });
65
-
66
65
this .servletRequest .setMethod ("GET" );
67
66
68
67
WebSocketHttpHeaders headers = new WebSocketHttpHeaders (this .request .getHeaders ());
@@ -73,22 +72,20 @@ public void supportedSubProtocols() throws Exception {
73
72
headers .setSecWebSocketProtocol ("STOMP" );
74
73
75
74
WebSocketHandler handler = new TextWebSocketHandler ();
76
- Map <String , Object > attributes = Collections .< String , Object > emptyMap ();
75
+ Map <String , Object > attributes = Collections .emptyMap ();
77
76
this .handshakeHandler .doHandshake (this .request , this .response , handler , attributes );
78
77
79
- verify (this .upgradeStrategy ).upgrade (this .request , this .response ,
80
- "STOMP" , Collections .< WebSocketExtension > emptyList (), null , handler , attributes );
78
+ verify (this .upgradeStrategy ).upgrade (this .request , this .response , "STOMP" ,
79
+ Collections .emptyList (), null , handler , attributes );
81
80
}
82
81
83
-
84
82
@ Test
85
- public void supportedExtensions () throws Exception {
86
-
83
+ public void supportedExtensions () {
87
84
WebSocketExtension extension1 = new WebSocketExtension ("ext1" );
88
85
WebSocketExtension extension2 = new WebSocketExtension ("ext2" );
89
86
90
87
given (this .upgradeStrategy .getSupportedVersions ()).willReturn (new String [] {"13" });
91
- given (this .upgradeStrategy .getSupportedExtensions (this .request )).willReturn (Arrays . asList (extension1 ));
88
+ given (this .upgradeStrategy .getSupportedExtensions (this .request )).willReturn (Collections . singletonList (extension1 ));
92
89
93
90
this .servletRequest .setMethod ("GET" );
94
91
@@ -103,14 +100,13 @@ public void supportedExtensions() throws Exception {
103
100
Map <String , Object > attributes = Collections .<String , Object >emptyMap ();
104
101
this .handshakeHandler .doHandshake (this .request , this .response , handler , attributes );
105
102
106
- verify (this .upgradeStrategy ).upgrade (this .request , this .response , null , Arrays . asList ( extension1 ),
107
- null , handler , attributes );
103
+ verify (this .upgradeStrategy ).upgrade (this .request , this .response , null ,
104
+ Collections . singletonList ( extension1 ), null , handler , attributes );
108
105
}
109
106
110
107
@ Test
111
- public void subProtocolCapableHandler () throws Exception {
112
-
113
- given (this .upgradeStrategy .getSupportedVersions ()).willReturn (new String []{"13" });
108
+ public void subProtocolCapableHandler () {
109
+ given (this .upgradeStrategy .getSupportedVersions ()).willReturn (new String [] {"13" });
114
110
115
111
this .servletRequest .setMethod ("GET" );
116
112
@@ -125,14 +121,13 @@ public void subProtocolCapableHandler() throws Exception {
125
121
Map <String , Object > attributes = Collections .<String , Object >emptyMap ();
126
122
this .handshakeHandler .doHandshake (this .request , this .response , handler , attributes );
127
123
128
- verify (this .upgradeStrategy ).upgrade (this .request , this .response ,
129
- "v11.stomp" , Collections .< WebSocketExtension > emptyList (), null , handler , attributes );
124
+ verify (this .upgradeStrategy ).upgrade (this .request , this .response , "v11.stomp" ,
125
+ Collections .emptyList (), null , handler , attributes );
130
126
}
131
127
132
128
@ Test
133
- public void subProtocolCapableHandlerNoMatch () throws Exception {
134
-
135
- given (this .upgradeStrategy .getSupportedVersions ()).willReturn (new String []{"13" });
129
+ public void subProtocolCapableHandlerNoMatch () {
130
+ given (this .upgradeStrategy .getSupportedVersions ()).willReturn (new String [] {"13" });
136
131
137
132
this .servletRequest .setMethod ("GET" );
138
133
@@ -147,17 +142,16 @@ public void subProtocolCapableHandlerNoMatch() throws Exception {
147
142
Map <String , Object > attributes = Collections .<String , Object >emptyMap ();
148
143
this .handshakeHandler .doHandshake (this .request , this .response , handler , attributes );
149
144
150
- verify (this .upgradeStrategy ).upgrade (this .request , this .response ,
151
- null , Collections .< WebSocketExtension > emptyList (), null , handler , attributes );
145
+ verify (this .upgradeStrategy ).upgrade (this .request , this .response , null ,
146
+ Collections .emptyList (), null , handler , attributes );
152
147
}
153
148
154
149
155
150
private static class SubProtocolCapableHandler extends TextWebSocketHandler implements SubProtocolCapable {
156
151
157
152
private final List <String > subProtocols ;
158
153
159
-
160
- private SubProtocolCapableHandler (String ... subProtocols ) {
154
+ public SubProtocolCapableHandler (String ... subProtocols ) {
161
155
this .subProtocols = Arrays .asList (subProtocols );
162
156
}
163
157
0 commit comments