Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure interface types are initialized before inline mocking to av…
…oid blocking code of static initializers.
- Loading branch information
Showing
2 changed files
with
46 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
44 changes: 44 additions & 0 deletions
44
subprojects/inline/src/test/java/org/mockitoinline/HierarchyPreInitializationTest.java
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,44 @@ | ||
/* | ||
* Copyright (c) 2017 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
package org.mockitoinline; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
|
||
public class HierarchyPreInitializationTest { | ||
|
||
@Test | ||
@SuppressWarnings("CheckReturnValue") | ||
public void testOrder() { | ||
mock(MyClass.class); | ||
mock(TestSubInterface.class); | ||
} | ||
|
||
public interface TestInterface { | ||
|
||
@SuppressWarnings("unused") | ||
MyClass INSTANCE = new MyClass().probe(); | ||
} | ||
|
||
public interface TestSubInterface extends TestInterface { | ||
} | ||
|
||
public static class MyClass { | ||
|
||
private final Object obj; | ||
|
||
public MyClass() { | ||
obj = new Object(); | ||
} | ||
|
||
public MyClass probe() { | ||
if (obj == null) { | ||
throw new RuntimeException(); | ||
} | ||
return this; | ||
} | ||
} | ||
} |