Skip to content

Commit

Permalink
improve test case
Browse files Browse the repository at this point in the history
Change-Id: I49fc02ca5087d52e81611ab5bb65ae2911ccb12f
  • Loading branch information
javeme committed Apr 24, 2022
1 parent 0f2aef6 commit 90ba846
Showing 1 changed file with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testGetInternalState() {
Test1 test1 = newTest();
Assert.assertEquals(1, Whitebox.getInternalState(test1, "ivalue"));
Assert.assertEquals(2f, Whitebox.getInternalState(test1,
"test2.fvalue"));
"test2.finalValue"));
Assert.assertEquals("3", Whitebox.getInternalState(test1,
"test2.test3.str"));

Expand All @@ -65,7 +65,7 @@ public void testGetInternalState() {
});

Assert.assertThrows(RuntimeException.class, () -> {
Whitebox.getInternalState(test1, "test2.fvalue2");
Whitebox.getInternalState(test1, "test2.valueNotExist");
});
}

Expand All @@ -77,9 +77,9 @@ public void testSetInternalState() {
Assert.assertEquals(11, Whitebox.getInternalState(test1, "ivalue"));
Assert.assertEquals(11, test1.ivalue);

Whitebox.setInternalState(test1, "test2.fvalue", 22f);
Whitebox.setInternalState(test1, "test2.finalValue", 22f);
Assert.assertEquals(22f, Whitebox.getInternalState(test1,
"test2.fvalue"));
"test2.finalValue"));

Whitebox.setInternalState(test1, "test2.test3.str", "33");
Assert.assertEquals("33", Whitebox.getInternalState(test1,
Expand All @@ -90,23 +90,40 @@ public void testSetInternalState() {
});

Assert.assertThrows(RuntimeException.class, () -> {
Whitebox.setInternalState(test1, "test2.fvalue2", 22f);
Whitebox.setInternalState(test1, "test2.valueNotExist", 22f);
});

Assert.assertThrows(RuntimeException.class, () -> {
Whitebox.setInternalState(test1, "test2.fvalue", 22d);
Whitebox.setInternalState(test1, "test2.finalValue", 22d);
});

Assert.assertThrows(RuntimeException.class, () -> {
test1.test2 = null;
Whitebox.setInternalState(test1, "test2.finalValue", 22f);
}, e -> {
Assert.assertContains("Can't set value on null field",
e.getMessage());
});
}

@Test
public void testSetInternalFinalState() {
Test1 test1 = newTest();
Assert.assertEquals(1, test1.ivalueFinal);
Assert.assertEquals(1, test1.finalValue);

Whitebox.setInternalState(test1, "finalValue", 2);
Assert.assertEquals(2, Whitebox.getInternalState(test1, "finalValue"));

Whitebox.setInternalState(test1, "finalValue", 3);
Assert.assertEquals(3, Whitebox.getInternalState(test1, "finalValue"));

Whitebox.setInternalState(test1, "test2.finalValue", 22f);
Assert.assertEquals(22f, Whitebox.getInternalState(test1,
"test2.finalValue"));

Whitebox.setInternalState(test1, "ivalueFinal", 2);
Assert.assertEquals(2, Whitebox.getInternalState(test1, "ivalueFinal"));
// FIXME: seems don't take effect!!!
Assert.assertEquals(1, test1.ivalueFinal);
Assert.assertEquals(1, test1.finalValue);
Assert.assertEquals(2f, test1.test2.finalValue, 0f);
}

@Test
Expand Down Expand Up @@ -173,7 +190,7 @@ private static class Test1 {
private static int staticValue = 1;

private int ivalue = 1;
private final int ivalueFinal = 1;
private final int finalValue = 1;

private Test2 test2;
private TestSubClass test4;
Expand Down Expand Up @@ -211,11 +228,11 @@ private static int throwfunc2() throws Exception {
private static class Test2 {

private static int staticValue = 2;
private final float fvalue = 2;
private final float finalValue = 2f;
private Test3 test3;

private float value() {
return this.fvalue;
return this.finalValue;
}

private <T> T value(T o) {
Expand Down

0 comments on commit 90ba846

Please sign in to comment.