diff --git a/build.gradle b/build.gradle index d88b4d7..9e0d8c0 100644 --- a/build.gradle +++ b/build.gradle @@ -31,9 +31,13 @@ repositories { } dependencies { - api "org.mockito:mockito-core:3.6.28" + def mockitoVersion = "3.6.28" + + api "org.mockito:mockito-core:$mockitoVersion" api "org.testng:testng:7.1.0" + testImplementation "org.assertj:assertj-core:3.18.1" + testImplementation "org.mockito:mockito-inline:$mockitoVersion" } test { diff --git a/src/test/java/org/mockitousage/testng/StaticMockTest.java b/src/test/java/org/mockitousage/testng/StaticMockTest.java new file mode 100644 index 0000000..fd0aa22 --- /dev/null +++ b/src/test/java/org/mockitousage/testng/StaticMockTest.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 Mockito contributors + * This program is made available under the terms of the MIT License. + */ +package org.mockitousage.testng; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.testng.MockitoTestNGListener; +import org.testng.annotations.Listeners; +import org.testng.annotations.Test; + +@Listeners(MockitoTestNGListener.class) +public class StaticMockTest { + + static class Dummy { + static String foo() { + return "foo"; + } + } + + @Mock + private MockedStatic dummy; + + @Test + public void simple_static_mock() { + assertThat(Dummy.foo()).isNull(); + } + + @Test + public void verify_static_method() { + // given + dummy.when(Dummy::foo).thenReturn("bar"); + + // when + assertThat(Dummy.foo()).isEqualTo("bar"); + + // then + dummy.verify(Dummy::foo); + } +}