Skip to content

Commit 698e74f

Browse files
committed
WebSocketExtension#equals matches sub-classes too
Closes gh-26449
1 parent 51079a4 commit 698e74f

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/WebSocketExtension.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -103,7 +103,7 @@ public boolean equals(@Nullable Object other) {
103103
if (this == other) {
104104
return true;
105105
}
106-
if (other == null || getClass() != other.getClass()) {
106+
if (other == null || !WebSocketExtension.class.isAssignableFrom(other.getClass())) {
107107
return false;
108108
}
109109
WebSocketExtension otherExt = (WebSocketExtension) other;

spring-websocket/src/test/java/org/springframework/web/socket/WebSocketExtensionTests.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,11 @@
1818

1919
import java.util.List;
2020

21+
import org.glassfish.tyrus.core.TyrusExtension;
2122
import org.junit.jupiter.api.Test;
2223

24+
import org.springframework.web.socket.adapter.standard.StandardToWebSocketExtensionAdapter;
25+
2326
import static org.assertj.core.api.Assertions.assertThat;
2427

2528
/**
@@ -30,7 +33,9 @@ public class WebSocketExtensionTests {
3033

3134
@Test
3235
public void parseHeaderSingle() {
33-
List<WebSocketExtension> extensions = WebSocketExtension.parseExtensions("x-test-extension ; foo=bar ; bar=baz");
36+
List<WebSocketExtension> extensions =
37+
WebSocketExtension.parseExtensions("x-test-extension ; foo=bar ; bar=baz");
38+
3439
assertThat(extensions).hasSize(1);
3540
WebSocketExtension extension = extensions.get(0);
3641

@@ -42,9 +47,18 @@ public void parseHeaderSingle() {
4247

4348
@Test
4449
public void parseHeaderMultiple() {
45-
List<WebSocketExtension> extensions = WebSocketExtension.parseExtensions("x-foo-extension, x-bar-extension");
50+
List<WebSocketExtension> extensions =
51+
WebSocketExtension.parseExtensions("x-foo-extension, x-bar-extension");
52+
4653
assertThat(extensions.stream().map(WebSocketExtension::getName))
4754
.containsExactly("x-foo-extension", "x-bar-extension");
4855
}
4956

57+
@Test // gh-26449
58+
public void equality() {
59+
WebSocketExtension ext1 = new WebSocketExtension("myExtension");
60+
WebSocketExtension ext2 = new StandardToWebSocketExtensionAdapter(new TyrusExtension("myExtension"));
61+
62+
assertThat(ext1).isEqualTo(ext2);
63+
}
5064
}

0 commit comments

Comments
 (0)