-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |