"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "spring-websocket/src/test/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSessionTests.java" between
spring-framework-5.3.23.tar.gz and spring-framework-5.3.24.tar.gz

About: Spring Framework is an application framework for the Java platform and .NET Framework. Community edition.

StandardWebSocketSessionTests.java  (spring-framework-5.3.23):StandardWebSocketSessionTests.java  (spring-framework-5.3.24)
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
skipping to change at line 40 skipping to change at line 40
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.reset; import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions;
/** /**
* Unit tests for {@link org.springframework.web.socket.adapter.standard.Standar dWebSocketSession}. * Unit tests for {@link org.springframework.web.socket.adapter.standard.Standar dWebSocketSession}.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
@SuppressWarnings("resource")
public class StandardWebSocketSessionTests { public class StandardWebSocketSessionTests {
private final HttpHeaders headers = new HttpHeaders(); private final HttpHeaders headers = new HttpHeaders();
private final Map<String, Object> attributes = new HashMap<>(); private final Map<String, Object> attributes = new HashMap<>();
@Test @Test
@SuppressWarnings("resource") @SuppressWarnings("resource")
public void getPrincipalWithConstructorArg() { public void getPrincipalWithConstructorArg() {
TestPrincipal user = new TestPrincipal("joe"); TestPrincipal user = new TestPrincipal("joe");
StandardWebSocketSession session = new StandardWebSocketSession(t his.headers, this.attributes, null, null, user); StandardWebSocketSession session = new StandardWebSocketSession(t his.headers, this.attributes, null, null, user);
assertThat(session.getPrincipal()).isSameAs(user); assertThat(session.getPrincipal()).isSameAs(user);
} }
@Test @Test
@SuppressWarnings("resource")
public void getPrincipalWithNativeSession() { public void getPrincipalWithNativeSession() {
TestPrincipal user = new TestPrincipal("joe"); TestPrincipal user = new TestPrincipal("joe");
Session nativeSession = Mockito.mock(Session.class); Session nativeSession = Mockito.mock(Session.class);
given(nativeSession.getUserPrincipal()).willReturn(user); given(nativeSession.getUserPrincipal()).willReturn(user);
StandardWebSocketSession session = new StandardWebSocketSession(t his.headers, this.attributes, null, null); StandardWebSocketSession session = new StandardWebSocketSession(t his.headers, this.attributes, null, null);
session.initializeNativeSession(nativeSession); session.initializeNativeSession(nativeSession);
assertThat(session.getPrincipal()).isSameAs(user); assertThat(session.getPrincipal()).isSameAs(user);
} }
@Test @Test
@SuppressWarnings("resource")
public void getPrincipalNone() { public void getPrincipalNone() {
Session nativeSession = Mockito.mock(Session.class); Session nativeSession = Mockito.mock(Session.class);
given(nativeSession.getUserPrincipal()).willReturn(null); given(nativeSession.getUserPrincipal()).willReturn(null);
StandardWebSocketSession session = new StandardWebSocketSession(t his.headers, this.attributes, null, null); StandardWebSocketSession session = new StandardWebSocketSession(t his.headers, this.attributes, null, null);
session.initializeNativeSession(nativeSession); session.initializeNativeSession(nativeSession);
reset(nativeSession); reset(nativeSession);
assertThat(session.getPrincipal()).isNull(); assertThat(session.getPrincipal()).isNull();
verifyNoMoreInteractions(nativeSession); verifyNoMoreInteractions(nativeSession);
} }
@Test @Test
@SuppressWarnings("resource")
public void getAcceptedProtocol() { public void getAcceptedProtocol() {
String protocol = "foo"; String protocol = "foo";
Session nativeSession = Mockito.mock(Session.class); Session nativeSession = Mockito.mock(Session.class);
given(nativeSession.getNegotiatedSubprotocol()).willReturn(protoc ol); given(nativeSession.getNegotiatedSubprotocol()).willReturn(protoc ol);
StandardWebSocketSession session = new StandardWebSocketSession(t his.headers, this.attributes, null, null); StandardWebSocketSession session = new StandardWebSocketSession(t his.headers, this.attributes, null, null);
session.initializeNativeSession(nativeSession); session.initializeNativeSession(nativeSession);
reset(nativeSession); reset(nativeSession);
assertThat(session.getAcceptedProtocol()).isEqualTo(protocol); assertThat(session.getAcceptedProtocol()).isEqualTo(protocol);
verifyNoMoreInteractions(nativeSession); verifyNoMoreInteractions(nativeSession);
} }
@Test // gh-29315
public void addAttributesWithNullKeyOrValue() {
this.attributes.put(null, "value");
this.attributes.put("key", null);
this.attributes.put("foo", "bar");
assertThat(new StandardWebSocketSession(this.headers, this.attrib
utes, null, null).getAttributes())
.hasSize(1).containsEntry("foo", "bar");
}
} }
 End of changes. 6 change blocks. 
4 lines changed or deleted 13 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)