This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git
The following commit(s) were added to refs/heads/master by this push:
new eff2d7408 [OPENMEETINGS-2733] some Sonar issues are addressed
eff2d7408 is described below
commit eff2d74083f9971557992d2c5e37eb706a2369ce
Author: Maxim Solodovnik <[email protected]>
AuthorDate: Wed May 18 22:18:25 2022 +0700
[OPENMEETINGS-2733] some Sonar issues are addressed
---
.../org/apache/openmeetings/TestConnection.java | 29 ----------------------
.../openmeetings/core/remote/BaseMockedTest.java | 16 +++++++-----
.../core/remote/TestNotConnectedMocked.java | 28 ++++++++++++++++++++-
3 files changed, 37 insertions(+), 36 deletions(-)
diff --git
a/openmeetings-core/src/test/java/org/apache/openmeetings/TestConnection.java
b/openmeetings-core/src/test/java/org/apache/openmeetings/TestConnection.java
deleted file mode 100644
index b3174f117..000000000
---
a/openmeetings-core/src/test/java/org/apache/openmeetings/TestConnection.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License") + you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.openmeetings;
-
-import org.junit.jupiter.api.Test;
-
-class TestConnection {
-
- @Test
- void testNoop() {
- //no-op
- }
-}
diff --git
a/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/BaseMockedTest.java
b/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/BaseMockedTest.java
index ff8549d3a..a19a3ca6d 100644
---
a/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/BaseMockedTest.java
+++
b/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/BaseMockedTest.java
@@ -97,6 +97,15 @@ public class BaseMockedTest {
handler.init();
}
+ void mockWs(MockedStatic<WebSocketHelper> wsHelperMock) {
+ wsHelperMock.when(() ->
WebSocketHelper.sendClient(any(IWsClient.class),
any(JSONObject.class))).thenAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) throws
Throwable {
+ return null;
+ }
+ });
+ }
+
void runWrapped(Runnable task) {
try (MockedStatic<AbstractStream> streamMock =
mockStatic(AbstractStream.class);
MockedStatic<WebSocketHelper> wsHelperMock =
mockStatic(WebSocketHelper.class);
@@ -108,12 +117,7 @@ public class BaseMockedTest {
Set<Object> mocks = newMockSafeHashSet();
new MockScanner(this,
BaseMockedTest.class).addPreparedMocks(mocks);
new MockScanner(this,
this.getClass()).addPreparedMocks(mocks);
- wsHelperMock.when(() ->
WebSocketHelper.sendClient(any(IWsClient.class),
any(JSONObject.class))).thenAnswer(new Answer<Void>() {
- @Override
- public Void answer(InvocationOnMock invocation)
throws Throwable {
- return null;
- }
- });
+ mockWs(wsHelperMock);
streamMock.when(() ->
AbstractStream.createWebRtcEndpoint(any(MediaPipeline.class), anyBoolean(),
any())).thenReturn(mock(WebRtcEndpoint.class));
streamMock.when(() ->
AbstractStream.createRecorderEndpoint(any(MediaPipeline.class), anyString(),
any(MediaProfileSpecType.class))).thenReturn(mock(RecorderEndpoint.class));
streamMock.when(() ->
AbstractStream.createPlayerEndpoint(any(MediaPipeline.class),
anyString())).thenReturn(mock(PlayerEndpoint.class));
diff --git
a/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestNotConnectedMocked.java
b/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestNotConnectedMocked.java
index 7f5f3c77f..e0eba9350 100644
---
a/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestNotConnectedMocked.java
+++
b/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestNotConnectedMocked.java
@@ -21,15 +21,41 @@ package org.apache.openmeetings.core.remote;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.times;
+import static org.mockito.internal.util.collections.Sets.newMockSafeHashSet;
+import java.util.Set;
+import java.util.function.Consumer;
+
+import org.apache.openmeetings.core.util.WebSocketHelper;
import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.internal.configuration.injection.scanner.MockScanner;
import com.github.openjson.JSONObject;
class TestNotConnectedMocked extends BaseMockedTest {
+ private void wrapWs(Consumer<MockedStatic<WebSocketHelper>> task) {
+ try (MockedStatic<WebSocketHelper> wsHelperMock =
mockStatic(WebSocketHelper.class)) {
+ Set<Object> mocks = newMockSafeHashSet();
+ new MockScanner(this,
TestNotConnectedMocked.class).addPreparedMocks(mocks);
+ new MockScanner(this,
this.getClass()).addPreparedMocks(mocks);
+ mockWs(wsHelperMock);
+ task.accept(wsHelperMock);
+ }
+ }
+
@Test
void testNotConnected() {
- handler.onMessage(null, getBaseMsg());
+ wrapWs(wsHelperMock -> {
+ handler.onMessage(null, getBaseMsg());
+ wsHelperMock.verify(
+ () ->
WebSocketHelper.sendClient(Mockito.isNull(), any(JSONObject.class))
+ , times(1));
+ });
}
@Test