From e0fcbc401041178fd54275a46a774c4d83578036 Mon Sep 17 00:00:00 2001 From: iwangjie <345127857@qq.com> Date: Wed, 26 Apr 2023 21:25:28 +0800 Subject: [PATCH] add mockito dependency. --- hippo4j-common/pom.xml | 5 +++ .../java/cn/hippo4j/common/MockitoTests.java | 37 +++++++++++++------ pom.xml | 11 +++++- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/hippo4j-common/pom.xml b/hippo4j-common/pom.xml index 2b5cb26a..e5be28cf 100644 --- a/hippo4j-common/pom.xml +++ b/hippo4j-common/pom.xml @@ -59,6 +59,11 @@ 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 index cf3b28ae..7673709d 100644 --- a/hippo4j-common/src/test/java/cn/hippo4j/common/MockitoTests.java +++ b/hippo4j-common/src/test/java/cn/hippo4j/common/MockitoTests.java @@ -1,33 +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.InjectMocks; import org.mockito.Mock; +import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; -import static org.mockito.ArgumentMatchers.anyInt; - -/** - * Mockito 集成测试 - * - * @author 王杰 - * So close, so far away - */ @ExtendWith(MockitoExtension.class) -public class MockitoTests { +class MockitoTests { @Mock List list; - @Test void mockTests() { Mockito.when(list.get(1)).thenReturn("mock success."); - Assertions.assertEquals("mock success.",list.get(1)); + 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 a7e9635b..6dc356a5 100644 --- a/pom.xml +++ b/pom.xml @@ -127,12 +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} +