Skip to content

Commit

Permalink
Unnecessary use of fully qualified name 'Mockito.mock' #3049
Browse files Browse the repository at this point in the history
  • Loading branch information
yurake committed Feb 15, 2023
1 parent 5144e94 commit 0d30017
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package webapp.tier.service.socket;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import javax.inject.Inject;
import javax.websocket.RemoteEndpoint;
Expand All @@ -24,7 +25,7 @@ class ActiveMqSocketTest {

@Test
void testOnOpen() {
Session session = Mockito.mock(Session.class);
Session session = mock(Session.class);
try {
Mockito.when(session.getId()).thenReturn(id);
socket.onOpen(session);
Expand All @@ -36,7 +37,7 @@ void testOnOpen() {

@Test
void testOnClose() {
Session session = Mockito.mock(Session.class);
Session session = mock(Session.class);
try {
Mockito.when(session.getId()).thenReturn(id);
socket.onOpen(session);
Expand All @@ -49,7 +50,7 @@ void testOnClose() {

@Test
void testOnError() {
Session session = Mockito.mock(Session.class);
Session session = mock(Session.class);
try {
Mockito.when(session.getId()).thenReturn(id);
socket.onOpen(session);
Expand All @@ -62,9 +63,9 @@ void testOnError() {

@Test
void testOnMessage() {
Session session = Mockito.mock(Session.class);
Session session = mock(Session.class);
try {
RemoteEndpoint.Async async = Mockito.mock(RemoteEndpoint.Async.class);
RemoteEndpoint.Async async = mock(RemoteEndpoint.Async.class);
Mockito.when(session.getId()).thenReturn(id);
Mockito.when(session.getAsyncRemote()).thenReturn(async);
socket.onOpen(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;
Expand All @@ -27,7 +28,7 @@ void testCallDown() {
void testCallUp() throws IOException, TimeoutException {
ReadinessHealthCheckHazelcast hc = new ReadinessHealthCheckHazelcast() {
protected HazelcastServiceStatus createHazelcastStatus() {
HazelcastServiceStatus mock = Mockito.mock(HazelcastServiceStatus.class);
HazelcastServiceStatus mock = mock(HazelcastServiceStatus.class);
Mockito.when(mock.isActive()).thenReturn(true);
return mock;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package webapp.tier.service;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.when;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
Expand All @@ -20,7 +18,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;

import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
Expand Down Expand Up @@ -58,7 +55,7 @@ void testPutMsgHazelcast() throws NoSuchAlgorithmException {

@Test
void testPutMsgHazelcastError() {
HazelcastInstance mockInstanceError = Mockito.mock(HazelcastInstance.class);
HazelcastInstance mockInstanceError = mock(HazelcastInstance.class);
when(mockInstanceError.getMap(ArgumentMatchers.any()))
.thenThrow(new IllegalStateException());
try {
Expand All @@ -85,7 +82,7 @@ void testGetMsgHazelcast() {

@Test
void testGetMsgHazelcastError() {
HazelcastInstance mockInstanceError = Mockito.mock(HazelcastInstance.class);
HazelcastInstance mockInstanceError = mock(HazelcastInstance.class);
when(mockInstanceError.getMap(ArgumentMatchers.any()))
.thenThrow(new IllegalStateException());
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package webapp.tier.service;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.when;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
Expand All @@ -18,7 +16,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;

import com.hazelcast.collection.IQueue;
import com.hazelcast.core.Hazelcast;
Expand Down Expand Up @@ -63,7 +60,7 @@ void testPutQueueHazelcast() {

@Test
void testPutQueueHazelcastError() {
HazelcastInstance mockInstanceError = Mockito.mock(HazelcastInstance.class);
HazelcastInstance mockInstanceError = mock(HazelcastInstance.class);
when(mockInstanceError.getQueue(ArgumentMatchers.any()))
.thenThrow(new IllegalStateException());
assertThat(svc.putMsg(mockInstanceError).getFullmsg(), containsString(respbody));
Expand Down Expand Up @@ -96,7 +93,7 @@ void testGetQueueHazelcast() throws NoSuchAlgorithmException, InterruptedExcepti

@Test
void testGetQueueHazelcastError() {
HazelcastInstance mockInstanceError = Mockito.mock(HazelcastInstance.class);
HazelcastInstance mockInstanceError = mock(HazelcastInstance.class);
when(mockInstanceError.getQueue(ArgumentMatchers.any()))
.thenThrow(new IllegalStateException());
assertThat(svc.getMsg(mockInstanceError).getMessage(), is("Unexpected Error"));
Expand All @@ -105,8 +102,8 @@ void testGetQueueHazelcastError() {
@SuppressWarnings("unchecked")
@Test
void testGetQueueHazelcastObjectNullError() {
HazelcastInstance mocknull = Mockito.mock(HazelcastInstance.class);
IQueue<Object> mockqueue = Mockito.mock(IQueue.class);
HazelcastInstance mocknull = mock(HazelcastInstance.class);
IQueue<Object> mockqueue = mock(IQueue.class);
when(mocknull.getQueue(ArgumentMatchers.any())).thenReturn(mockqueue);
when(mockqueue.poll()).thenReturn(null);
assertThat(svc.getMsg(mocknull).getFullmsg(), containsString("No Data."));
Expand All @@ -115,8 +112,8 @@ void testGetQueueHazelcastObjectNullError() {
@SuppressWarnings("unchecked")
@Test
void testGetQueueHazelcastObjectEmptyError() {
HazelcastInstance mocknull = Mockito.mock(HazelcastInstance.class);
IQueue<Object> mockqueue = Mockito.mock(IQueue.class);
HazelcastInstance mocknull = mock(HazelcastInstance.class);
IQueue<Object> mockqueue = mock(IQueue.class);
when(mocknull.getQueue(ArgumentMatchers.any())).thenReturn(mockqueue);
when(mockqueue.poll()).thenReturn("");
assertThat(svc.getMsg(mocknull).getFullmsg(), containsString("No Data."));
Expand All @@ -142,7 +139,7 @@ void testPublishHazelcast() {

@Test
void testPublishHazelcastError() {
HazelcastInstance mockInstanceError = Mockito.mock(HazelcastInstance.class);
HazelcastInstance mockInstanceError = mock(HazelcastInstance.class);
when(mockInstanceError.getTopic(ArgumentMatchers.any()))
.thenThrow(new IllegalStateException());
assertThat(svc.publishMsg(mockInstanceError).getFullmsg(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package webapp.tier.service.socket;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import javax.inject.Inject;
import javax.websocket.RemoteEndpoint;
Expand All @@ -24,7 +25,7 @@ class HazelcastSocketTest {

@Test
void testOnOpen() {
Session session = Mockito.mock(Session.class);
Session session = mock(Session.class);
try {
Mockito.when(session.getId()).thenReturn(id);
socket.onOpen(session);
Expand All @@ -36,7 +37,7 @@ void testOnOpen() {

@Test
void testOnClose() {
Session session = Mockito.mock(Session.class);
Session session = mock(Session.class);
try {
Mockito.when(session.getId()).thenReturn(id);
socket.onOpen(session);
Expand All @@ -49,7 +50,7 @@ void testOnClose() {

@Test
void testOnError() {
Session session = Mockito.mock(Session.class);
Session session = mock(Session.class);
try {
Mockito.when(session.getId()).thenReturn(id);
socket.onOpen(session);
Expand All @@ -62,9 +63,9 @@ void testOnError() {

@Test
void testOnMessage() {
Session session = Mockito.mock(Session.class);
Session session = mock(Session.class);
try {
RemoteEndpoint.Async async = Mockito.mock(RemoteEndpoint.Async.class);
RemoteEndpoint.Async async = mock(RemoteEndpoint.Async.class);
Mockito.when(session.getId()).thenReturn(id);
Mockito.when(session.getAsyncRemote()).thenReturn(async);
socket.onOpen(session);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package webapp.tier.resource;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.when;

import java.security.NoSuchAlgorithmException;

import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import com.whalin.MemCached.MemCachedClient;

Expand All @@ -25,7 +25,7 @@ class MemcachedResourceTest {

@Test
void testSet() throws NoSuchAlgorithmException, RuntimeException {
MemCachedClient mcc = Mockito.mock(MemCachedClient.class);
MemCachedClient mcc = mock(MemCachedClient.class);
MsgBean msgbean = new MsgBean(CreateId.createid(), "test", "Test");
when(svc.createMemCachedClient()).thenReturn(mcc);
when(svc.setMsg(mcc)).thenReturn(msgbean);
Expand All @@ -40,7 +40,7 @@ void testSet() throws NoSuchAlgorithmException, RuntimeException {

@Test
void testGet() throws NoSuchAlgorithmException {
MemCachedClient mcc = Mockito.mock(MemCachedClient.class);
MemCachedClient mcc = mock(MemCachedClient.class);
MsgBean msgbean = new MsgBean(CreateId.createid(), "test", "Test");
when(svc.createMemCachedClient()).thenReturn(mcc);
when(svc.getMsg(mcc)).thenReturn(msgbean);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import javax.inject.Inject;

Expand All @@ -25,7 +26,7 @@ class MemcachedServiceTest {

@Test
void testSetMemcached() {
MemCachedClient mcc = Mockito.mock(MemCachedClient.class);
MemCachedClient mcc = mock(MemCachedClient.class);
Mockito.when(mcc.set(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(true);
try {
MsgBean msgbean = svcMock.setMsg(mcc);
Expand All @@ -51,7 +52,7 @@ void testSetMemcachedError() {
void testGetMemcached() {
Object obj = "11111111";
String msg = "Hello k8s-3tier-webapp with quarkus";
MemCachedClient mcc = Mockito.mock(MemCachedClient.class);
MemCachedClient mcc = mock(MemCachedClient.class);
Mockito.when(mcc.get("id")).thenReturn(obj.toString());
Mockito.when(mcc.get("msg")).thenReturn(msg);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ class MongodbServiceTest {
@Test
@SuppressWarnings("unchecked")
void testInsertMysql() throws NoSuchAlgorithmException {
MongoCollection<Document> col = Mockito.mock(MongoCollection.class);
MongoCollection<Document> col = mock(MongoCollection.class);
when(col.insertOne(ArgumentMatchers.any())).thenReturn(null);
assertThat(mongosvc.insertMsg(col).getFullmsg(), containsString(respbody));
}

@Test
@SuppressWarnings("unchecked")
void testSelectMsgIsEmpty() {
MongoCursor<Document> cursor = Mockito.mock(MongoCursor.class);
FindIterable<Document> ite = Mockito.mock(FindIterable.class);
MongoCollection<Document> col = Mockito.mock(MongoCollection.class);
MongoCursor<Document> cursor = mock(MongoCursor.class);
FindIterable<Document> ite = mock(FindIterable.class);
MongoCollection<Document> col = mock(MongoCollection.class);
when(col.find()).thenReturn(ite);
when(ite.iterator()).thenReturn(cursor);
mongosvc.selectMsg(col);
Expand All @@ -58,9 +58,9 @@ void testSelectMsgWithMessage() {
map.put("id", 1111);
map.put("msg", "Test");
Document document = new Document(map);
MongoCursor<Document> cursor = Mockito.mock(MongoCursor.class);
FindIterable<Document> ite = Mockito.mock(FindIterable.class);
MongoCollection<Document> col = Mockito.mock(MongoCollection.class);
MongoCursor<Document> cursor = mock(MongoCursor.class);
FindIterable<Document> ite = mock(FindIterable.class);
MongoCollection<Document> col = mock(MongoCollection.class);
when(cursor.hasNext()).thenReturn(true).thenReturn(false);
when(cursor.next()).thenReturn(document);
when(ite.iterator()).thenReturn(cursor);
Expand All @@ -75,7 +75,7 @@ void testSelectMsgWithMessage() {
@Test
@SuppressWarnings("unchecked")
void testDeleteMsg() {
MongoCollection<Document> col = Mockito.mock(MongoCollection.class);
MongoCollection<Document> col = mock(MongoCollection.class);
when(col.insertOne(ArgumentMatchers.any())).thenReturn(null);
assertThat(mongosvc.deleteMsg(col), is("Delete Msg Collection"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package webapp.tier.service.socket;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import javax.inject.Inject;
import javax.websocket.RemoteEndpoint;
Expand All @@ -24,7 +25,7 @@ class RabbitmqSocketTest {

@Test
void testOnOpen() {
Session session = Mockito.mock(Session.class);
Session session = mock(Session.class);
try {
Mockito.when(session.getId()).thenReturn(id);
socket.onOpen(session);
Expand All @@ -36,7 +37,7 @@ void testOnOpen() {

@Test
void testOnClose() {
Session session = Mockito.mock(Session.class);
Session session = mock(Session.class);
try {
Mockito.when(session.getId()).thenReturn(id);
socket.onOpen(session);
Expand All @@ -49,7 +50,7 @@ void testOnClose() {

@Test
void testOnError() {
Session session = Mockito.mock(Session.class);
Session session = mock(Session.class);
try {
Mockito.when(session.getId()).thenReturn(id);
socket.onOpen(session);
Expand All @@ -62,9 +63,9 @@ void testOnError() {

@Test
void testOnMessage() {
Session session = Mockito.mock(Session.class);
Session session = mock(Session.class);
try {
RemoteEndpoint.Async async = Mockito.mock(RemoteEndpoint.Async.class);
RemoteEndpoint.Async async = mock(RemoteEndpoint.Async.class);
Mockito.when(session.getId()).thenReturn(id);
Mockito.when(session.getAsyncRemote()).thenReturn(async);
socket.onOpen(session);
Expand Down
Loading

0 comments on commit 0d30017

Please sign in to comment.