View Javadoc
1   /*
2    * MIT License
3    * Copyright (c) 2006-2025 JMockit developers
4    * See LICENSE file for full license text.
5    */
6   package mockit.integration.junit4;
7   
8   import static org.junit.jupiter.api.Assertions.assertFalse;
9   import static org.junit.jupiter.api.Assertions.assertTrue;
10  
11  import org.junit.Test;
12  
13  public final class UseDependencyTest {
14      @Test
15      public void useMockedDependency() {
16          if (AnotherDependency.mockedAtSuiteLevel) {
17              assertFalse(AnotherDependency.alwaysTrue());
18          } else {
19              assertTrue(AnotherDependency.alwaysTrue());
20          }
21      }
22  
23      private static final boolean STATIC_FIELD = Dependency.alwaysTrue();
24      private final boolean instanceField = Dependency.alwaysTrue();
25  
26      @Test
27      public void useFieldSetThroughDirectInstanceInitializationRatherThanBeforeMethod() {
28          assertTrue(instanceField, "Dependency still mocked");
29      }
30  
31      @Test
32      public void useFieldSetThroughDirectClassInitializationRatherThanBeforeClassMethod() {
33          assertTrue(STATIC_FIELD, "Dependency still mocked");
34      }
35  }