Rename the Class
This commit is contained in:
parent
5b7dde1ae8
commit
756f70b29f
|
@ -5,10 +5,9 @@ import org.junit.Test;
|
|||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.VarHandle;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class VariableHandlesTest {
|
||||
public class VariableHandlesUnitTest {
|
||||
|
||||
public int publicTestVariable = 1;
|
||||
private int privateTestVariable = 1;
|
||||
|
@ -21,21 +20,21 @@ public class VariableHandlesTest {
|
|||
public void whenVariableHandleForPublicVariableIsCreated_ThenItIsInitializedProperly() throws NoSuchFieldException, IllegalAccessException {
|
||||
VarHandle PUBLIC_TEST_VARIABLE = MethodHandles
|
||||
.lookup()
|
||||
.in(VariableHandlesTest.class)
|
||||
.findVarHandle(VariableHandlesTest.class, "publicTestVariable", int.class);
|
||||
.in(VariableHandlesUnitTest.class)
|
||||
.findVarHandle(VariableHandlesUnitTest.class, "publicTestVariable", int.class);
|
||||
|
||||
assertEquals(1, PUBLIC_TEST_VARIABLE.coordinateTypes().size());
|
||||
assertEquals(VariableHandlesTest.class, PUBLIC_TEST_VARIABLE.coordinateTypes().get(0));
|
||||
assertEquals(VariableHandlesUnitTest.class, PUBLIC_TEST_VARIABLE.coordinateTypes().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVariableHandleForPrivateVariableIsCreated_ThenItIsInitializedProperly() throws NoSuchFieldException, IllegalAccessException {
|
||||
VarHandle PRIVATE_TEST_VARIABLE = MethodHandles
|
||||
.privateLookupIn(VariableHandlesTest.class, MethodHandles.lookup())
|
||||
.findVarHandle(VariableHandlesTest.class, "privateTestVariable", int.class);
|
||||
.privateLookupIn(VariableHandlesUnitTest.class, MethodHandles.lookup())
|
||||
.findVarHandle(VariableHandlesUnitTest.class, "privateTestVariable", int.class);
|
||||
|
||||
assertEquals(1, PRIVATE_TEST_VARIABLE.coordinateTypes().size());
|
||||
assertEquals(VariableHandlesTest.class, PRIVATE_TEST_VARIABLE.coordinateTypes().get(0));
|
||||
assertEquals(VariableHandlesUnitTest.class, PRIVATE_TEST_VARIABLE.coordinateTypes().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -51,8 +50,8 @@ public class VariableHandlesTest {
|
|||
public void givenVarHandle_whenGetIsInvoked_ThenValueOfVariableIsReturned() throws NoSuchFieldException, IllegalAccessException {
|
||||
VarHandle PUBLIC_TEST_VARIABLE = MethodHandles
|
||||
.lookup()
|
||||
.in(VariableHandlesTest.class)
|
||||
.findVarHandle(VariableHandlesTest.class, "publicTestVariable", int.class);
|
||||
.in(VariableHandlesUnitTest.class)
|
||||
.findVarHandle(VariableHandlesUnitTest.class, "publicTestVariable", int.class);
|
||||
|
||||
assertEquals(1, (int) PUBLIC_TEST_VARIABLE.get(this));
|
||||
}
|
||||
|
@ -61,8 +60,8 @@ public class VariableHandlesTest {
|
|||
public void givenVarHandle_whenSetIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException {
|
||||
VarHandle VARIABLE_TO_SET = MethodHandles
|
||||
.lookup()
|
||||
.in(VariableHandlesTest.class)
|
||||
.findVarHandle(VariableHandlesTest.class, "variableToSet", int.class);
|
||||
.in(VariableHandlesUnitTest.class)
|
||||
.findVarHandle(VariableHandlesUnitTest.class, "variableToSet", int.class);
|
||||
|
||||
VARIABLE_TO_SET.set(this, 15);
|
||||
assertEquals(15, (int) VARIABLE_TO_SET.get(this));
|
||||
|
@ -72,8 +71,8 @@ public class VariableHandlesTest {
|
|||
public void givenVarHandle_whenCompareAndSetIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException {
|
||||
VarHandle VARIABLE_TO_COMPARE_AND_SET = MethodHandles
|
||||
.lookup()
|
||||
.in(VariableHandlesTest.class)
|
||||
.findVarHandle(VariableHandlesTest.class, "variableToCompareAndSet", int.class);
|
||||
.in(VariableHandlesUnitTest.class)
|
||||
.findVarHandle(VariableHandlesUnitTest.class, "variableToCompareAndSet", int.class);
|
||||
|
||||
VARIABLE_TO_COMPARE_AND_SET.compareAndSet(this, 1, 100);
|
||||
assertEquals(100, (int) VARIABLE_TO_COMPARE_AND_SET.get(this));
|
||||
|
@ -83,8 +82,8 @@ public class VariableHandlesTest {
|
|||
public void givenVarHandle_whenGetAndAddIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException {
|
||||
VarHandle VARIABLE_TO_GET_AND_ADD = MethodHandles
|
||||
.lookup()
|
||||
.in(VariableHandlesTest.class)
|
||||
.findVarHandle(VariableHandlesTest.class, "variableToGetAndAdd", int.class);
|
||||
.in(VariableHandlesUnitTest.class)
|
||||
.findVarHandle(VariableHandlesUnitTest.class, "variableToGetAndAdd", int.class);
|
||||
|
||||
int before = (int) VARIABLE_TO_GET_AND_ADD.getAndAdd(this, 200);
|
||||
|
||||
|
@ -96,8 +95,8 @@ public class VariableHandlesTest {
|
|||
public void givenVarHandle_whenGetAndBitwiseOrIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException {
|
||||
VarHandle VARIABLE_TO_BITWISE_OR = MethodHandles
|
||||
.lookup()
|
||||
.in(VariableHandlesTest.class)
|
||||
.findVarHandle(VariableHandlesTest.class, "variableToBitwiseOr", byte.class);
|
||||
.in(VariableHandlesUnitTest.class)
|
||||
.findVarHandle(VariableHandlesUnitTest.class, "variableToBitwiseOr", byte.class);
|
||||
byte before = (byte) VARIABLE_TO_BITWISE_OR.getAndBitwiseOr(this, (byte) 127);
|
||||
|
||||
assertEquals(0, before);
|
||||
|
|
Loading…
Reference in New Issue