1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.bcel.generic;
21
22 import static org.junit.jupiter.api.Assertions.assertEquals;
23 import static org.junit.jupiter.api.Assertions.assertFalse;
24 import static org.junit.jupiter.api.Assertions.assertNotNull;
25 import static org.junit.jupiter.api.Assertions.assertNull;
26 import static org.junit.jupiter.api.Assertions.assertTrue;
27
28 import org.apache.bcel.Const;
29 import org.apache.bcel.classfile.ConstantLong;
30 import org.apache.bcel.classfile.ConstantPool;
31 import org.apache.bcel.classfile.Field;
32 import org.junit.jupiter.api.Disabled;
33 import org.junit.jupiter.api.Test;
34 import org.junit.jupiter.params.ParameterizedTest;
35 import org.junit.jupiter.params.provider.ValueSource;
36
37
38
39
40 class FieldGenTest {
41
42 @Test
43 @Disabled
44 void testBCELComparator() throws Exception {
45 final ConstantLong[] constantPool = { new ConstantLong(0), new ConstantLong(0) };
46 final FieldGen obj = new FieldGen(new Field(0, 0, 0, null, new ConstantPool(constantPool)), new ConstantPoolGen(constantPool));
47 assertTrue(FieldGen.getComparator().equals(null, null));
48 assertTrue(FieldGen.getComparator().equals(obj, obj));
49 assertFalse(FieldGen.getComparator().equals(obj, null));
50 assertFalse(FieldGen.getComparator().equals(null, obj));
51 }
52
53 @ParameterizedTest
54 @ValueSource(booleans = { false, true })
55 void testBooleanInitValue(final boolean value) {
56 final FieldGen fg = new FieldGen(Const.ACC_PUBLIC | Const.ACC_STATIC | Const.ACC_FINAL, Type.BOOLEAN, "VALUE", new ConstantPoolGen());
57 fg.setInitValue(value);
58 final Field field = fg.getField();
59 assertNotNull(field.getConstantValue());
60 assertEquals(value ? 1 : 0, field.getConstantPool().getConstantInteger(field.getConstantValue().getConstantValueIndex()).getBytes());
61 }
62
63 @ParameterizedTest
64 @ValueSource(booleans = { false, true })
65 void testBooleanInitValueReplacement(final boolean value) {
66 final FieldGen fg = new FieldGen(Const.ACC_PUBLIC | Const.ACC_STATIC | Const.ACC_FINAL, Type.BOOLEAN, "VALUE", new ConstantPoolGen());
67 fg.setInitValue(!value);
68 fg.setInitValue(value);
69 final Field field = fg.getField();
70 assertNotNull(field.getConstantValue());
71 assertEquals(value ? 1 : 0, field.getConstantPool().getConstantInteger(field.getConstantValue().getConstantValueIndex()).getBytes());
72 }
73
74 @ParameterizedTest
75 @ValueSource(booleans = { false, true })
76 void testCancelBooleanInitValue(final boolean value) {
77 final FieldGen fg = new FieldGen(Const.ACC_PUBLIC | Const.ACC_STATIC | Const.ACC_FINAL, Type.BOOLEAN, "VALUE", new ConstantPoolGen());
78 fg.setInitValue(value);
79 fg.cancelInitValue();
80 assertNull(fg.getField().getConstantValue());
81 }
82 }