From cdeae3010fecbb94419717dc5d93fcad6a6f3744 Mon Sep 17 00:00:00 2001 From: iwangjie <345127857@qq.com> Date: Wed, 26 Apr 2023 22:02:23 +0800 Subject: [PATCH] add mockito dependencey. (#1183) * mockito_dep * add mockito dependency. --- hippo4j-common/pom.xml | 10 ++++ .../java/cn/hippo4j/common/MockitoTests.java | 46 +++++++++++++++++++ pom.xml | 16 +++++++ 3 files changed, 72 insertions(+) create mode 100644 hippo4j-common/src/test/java/cn/hippo4j/common/MockitoTests.java diff --git a/hippo4j-common/pom.xml b/hippo4j-common/pom.xml index efba01a7..e5be28cf 100644 --- a/hippo4j-common/pom.xml +++ b/hippo4j-common/pom.xml @@ -54,6 +54,16 @@ spring-boot-starter-test test + + org.mockito + mockito-core + test + + + org.mockito + mockito-inline + test + com.github.ben-manes.caffeine caffeine diff --git a/hippo4j-common/src/test/java/cn/hippo4j/common/MockitoTests.java b/hippo4j-common/src/test/java/cn/hippo4j/common/MockitoTests.java new file mode 100644 index 00000000..7673709d --- /dev/null +++ b/hippo4j-common/src/test/java/cn/hippo4j/common/MockitoTests.java @@ -0,0 +1,46 @@ +/* + * 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 cn.hippo4j.common; + +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; + +@ExtendWith(MockitoExtension.class) +class MockitoTests { + + @Mock + List list; + + @Test + void mockTests() { + Mockito.when(list.get(1)).thenReturn("mock success."); + Assertions.assertEquals("mock success.", list.get(1)); + try (final MockedStatic mockStatic = Mockito.mockStatic(StringUtils.class)) { + mockStatic.when(() -> StringUtils.trim("")).thenReturn("测试"); + Assertions.assertEquals("测试", StringUtils.trim("")); + } + } +} diff --git a/pom.xml b/pom.xml index f19c94e8..6dc356a5 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,7 @@ 0.9.0 2.11.1 2.1.214 + 3.12.4 3.0.5 2.6.12 @@ -126,6 +127,21 @@ netty-all ${netty.version} + + org.mockito + mockito-core + ${mockito.version} + + + org.mockito + mockito-inline + ${mockito.version} + + + org.mockito + mockito-junit-jupiter + ${mockito.version} +