Skip to content

Commit 4312e11

Browse files
authored
DecoratingHttp2ConnectionEncoder.consumeRemoteSettings must not throw if delegate is instance of Http2SettingsReceivedConsumer (netty#9343)
Motivation: b3dba31 introduced the concept of Http2SettingsReceivedConsumer but did not correctly inplement DecoratingHttp2ConnectionEncoder.consumeRemoteSettings(...). Modifications: - Add missing `else` around the throws - Add unit tests Result: Correctly implement DecoratingHttp2ConnectionEncoder.consumeRemoteSettings(...)
1 parent 91d6e0e commit 4312e11

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

codec-http2/src/main/java/io/netty/handler/codec/http2/DecoratingHttp2ConnectionEncoder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ public void remoteSettings(Http2Settings settings) throws Http2Exception {
6565
public void consumeReceivedSettings(Http2Settings settings) {
6666
if (delegate instanceof Http2SettingsReceivedConsumer) {
6767
((Http2SettingsReceivedConsumer) delegate).consumeReceivedSettings(settings);
68+
} else {
69+
throw new IllegalStateException("delegate " + delegate + " is not an instance of " +
70+
Http2SettingsReceivedConsumer.class);
6871
}
69-
throw new IllegalStateException("delegate " + delegate + " is not an instance of " +
70-
Http2SettingsReceivedConsumer.class);
7172
}
7273
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2019 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License, version 2.0 (the
5+
* "License"); you may not use this file except in compliance with the License. You may obtain a
6+
* copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under the License
11+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
* or implied. See the License for the specific language governing permissions and limitations under
13+
* the License.
14+
*/
15+
package io.netty.handler.codec.http2;
16+
17+
import org.junit.Test;
18+
import static org.mockito.Mockito.eq;
19+
import static org.mockito.Mockito.mock;
20+
import static org.mockito.Mockito.verify;
21+
import static org.mockito.Mockito.times;
22+
23+
public class DecoratingHttp2ConnectionEncoderTest {
24+
25+
@Test(expected = IllegalStateException.class)
26+
public void testConsumeReceivedSettingsThrows() {
27+
Http2ConnectionEncoder encoder = mock(Http2ConnectionEncoder.class);
28+
DecoratingHttp2ConnectionEncoder decoratingHttp2ConnectionEncoder =
29+
new DecoratingHttp2ConnectionEncoder(encoder);
30+
decoratingHttp2ConnectionEncoder.consumeReceivedSettings(Http2Settings.defaultSettings());
31+
}
32+
33+
@Test
34+
public void testConsumeReceivedSettingsDelegate() {
35+
TestHttp2ConnectionEncoder encoder = mock(TestHttp2ConnectionEncoder.class);
36+
DecoratingHttp2ConnectionEncoder decoratingHttp2ConnectionEncoder =
37+
new DecoratingHttp2ConnectionEncoder(encoder);
38+
39+
Http2Settings settings = Http2Settings.defaultSettings();
40+
decoratingHttp2ConnectionEncoder.consumeReceivedSettings(Http2Settings.defaultSettings());
41+
verify(encoder, times(1)).consumeReceivedSettings(eq(settings));
42+
}
43+
44+
private interface TestHttp2ConnectionEncoder extends Http2ConnectionEncoder, Http2SettingsReceivedConsumer { }
45+
}

0 commit comments

Comments
 (0)