MCPcopy Create free account
hub / github.com/traneio/future / UnsafeTest

Class UnsafeTest

future-java/src/test/java/io/trane/future/UnsafeTest.java:7–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5import org.junit.Test;
6
7public class UnsafeTest {
8
9 class TestClass {
10 private volatile Object field = null;
11
12 public Object getField() {
13 return field;
14 }
15 }
16
17 @Test
18 public void unsafeInstance() {
19 assertEquals(Unsafe.instance, Unsafe.getDeclaredStaticField(sun.misc.Unsafe.class, "theUnsafe"));
20 }
21
22 @Test(expected = RuntimeException.class)
23 public void getDeclaredStaticField() {
24 Unsafe.getDeclaredStaticField(TestClass.class, "wrongField");
25 }
26
27 @Test
28 public void objectFieldOffset() throws NoSuchFieldException, SecurityException {
29 long actual = Unsafe.objectFieldOffset(TestClass.class, "field");
30 long expected = Unsafe.instance.objectFieldOffset(TestClass.class.getDeclaredField("field"));
31 assertEquals(actual, expected);
32 }
33
34 @Test(expected = RuntimeException.class)
35 public void objectFieldOffsetException() {
36 Unsafe.objectFieldOffset(TestClass.class, "wrongField");
37 }
38}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…