Bael 7757 (#16485)
* BAEL-7765: How to fix JsonParseException: Unexpected character (code 115) when parsing unquoted JSON in Jackson * BAEL-7757: How to solve MockitoException: the existing mock registration must be deregistered
This commit is contained in:
parent
f94b8d96ca
commit
5f0a95c784
|
@ -0,0 +1,40 @@
|
|||
package com.baeldung.mockito.mockstatic;
|
||||
|
||||
import com.baeldung.mockito.mockedstatic.StaticUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
|
||||
public class StaticMockRegistrationUnitTest {
|
||||
|
||||
private MockedStatic<StaticUtils> mockStatic;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Registering a static mock for UserService before each test
|
||||
mockStatic = mockStatic(StaticUtils.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
// Closing the mockStatic after each test
|
||||
mockStatic.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStaticMockRegistration_whenMocked_thenReturnsMockSuccessfully() {
|
||||
// Ensure that the static mock for UserService is registered
|
||||
assertTrue(Mockito.mockingDetails(StaticUtils.class).isMock());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAnotherStaticMockRegistration_whenMocked_thenReturnsMockSuccessfully() {
|
||||
// Ensure that the static mock for UserService is registered
|
||||
assertTrue(Mockito.mockingDetails(StaticUtils.class).isMock());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue