Skip to content

Commit

Permalink
Test for MockedStatic
Browse files Browse the repository at this point in the history
[skip release]
  • Loading branch information
slawekjaranowski committed Dec 10, 2020
1 parent 72cae31 commit 8ab741f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/org/mockitousage/testng/StaticMockTest.java
Original file line number Diff line number Diff line change
@@ -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> 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);
}
}

0 comments on commit 8ab741f

Please sign in to comment.