Skip to content

Commit 61f48fd

Browse files
committed
cleaning up unit tests and converting Java 8 statements to the equivalent Java 7 statements to satisfy IntelliJ
1 parent b5a1969 commit 61f48fd

File tree

6 files changed

+93
-265
lines changed

6 files changed

+93
-265
lines changed

core/src/test/java/oracle/weblogic/deploy/create/CustomBeanUtilsTest.java

Lines changed: 72 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package oracle.weblogic.deploy.create;
66

77
import org.junit.jupiter.api.Test;
8+
import org.junit.jupiter.api.function.Executable;
89

910
import static org.junit.jupiter.api.Assertions.assertEquals;
1011
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -14,77 +15,108 @@
1415
public class CustomBeanUtilsTest {
1516

1617
@Test
17-
public void testSimpleTypes() {
18-
Object result;
19-
20-
// boolean to boolean
21-
result = CustomBeanUtils.convertValue(Boolean.TRUE, Boolean.class);
18+
public void testBooleanValueToBooleanConversion() {
19+
Object result = CustomBeanUtils.convertValue(Boolean.TRUE, Boolean.class);
2220
assertEquals(Boolean.TRUE, result, "Boolean result does not match");
21+
}
2322

24-
// string to boolean
25-
result = CustomBeanUtils.convertValue("true", Boolean.class);
23+
@Test
24+
public void testStringToBooleanConversion() {
25+
Object result = CustomBeanUtils.convertValue("true", Boolean.class);
2626
assertEquals(Boolean.TRUE, result, "String to boolean result does not match");
27+
}
2728

28-
// character to character
29-
result = CustomBeanUtils.convertValue('x', Character.class);
29+
@Test
30+
public void testCharacterConversion() {
31+
Object result = CustomBeanUtils.convertValue('x', Character.class);
3032
assertEquals('x', result, "Character result does not match");
33+
}
3134

32-
// string to character
33-
result = CustomBeanUtils.convertValue("x", Character.class);
35+
@Test
36+
public void testStringToCharacterConversion() {
37+
Object result = CustomBeanUtils.convertValue("x", Character.class);
3438
assertEquals('x', result, "String to character result does not match");
39+
}
3540

36-
// string to double
37-
result = CustomBeanUtils.convertValue("123.4", Double.class);
38-
assertEquals(123.4, result, "String to double result does not match");
39-
40-
// string to float
41-
result = CustomBeanUtils.convertValue("123.4", Float.class);
42-
assertEquals(123.4f, result, "String to float result does not match");
43-
44-
// string to integer
45-
result = CustomBeanUtils.convertValue("1234", Integer.class);
41+
@Test
42+
public void testStringToIntegerConversion() {
43+
Object result = CustomBeanUtils.convertValue("1234", Integer.class);
4644
assertEquals(1234, result, "String to integer does not match");
45+
}
4746

48-
// string to long
49-
result = CustomBeanUtils.convertValue("1234", Long.class);
47+
@Test
48+
public void testStringToLongConversion() {
49+
Object result = CustomBeanUtils.convertValue("1234", Long.class);
5050
assertEquals(1234L, result, "Boolean text result does not match");
51+
}
52+
53+
@Test
54+
public void testStringToFloatConversion() {
55+
Object result = CustomBeanUtils.convertValue("123.4", Float.class);
56+
assertEquals(123.4f, result, "String to float result does not match");
57+
}
58+
59+
@Test
60+
public void testStringToDoubleConversion() {
61+
Object result = CustomBeanUtils.convertValue("123.4", Double.class);
62+
assertEquals(123.4, result, "String to double result does not match");
63+
}
5164

52-
// string to string
65+
@Test
66+
public void testStringToStringConversion() {
5367
String sourceText = "textValue";
54-
result = CustomBeanUtils.convertValue(sourceText, String.class);
68+
Object result = CustomBeanUtils.convertValue(sourceText, String.class);
5569
assertEquals(sourceText, result, "String result does not match");
56-
57-
// fail with bad numeric value
58-
assertThrows(IllegalArgumentException.class, () -> CustomBeanUtils.convertValue("1234X", Integer.class));
5970
}
6071

6172
@Test
62-
public void testArrayTypes() {
63-
Object result;
73+
public void testBadStringToIntegerConversionThrowsException() {
74+
assertThrows(IllegalArgumentException.class, new Executable() {
75+
@Override
76+
public void execute() throws Throwable {
77+
CustomBeanUtils.convertValue("1234X", Integer.class);
78+
}
79+
});
80+
}
6481

65-
// string[] to string[]
82+
@Test
83+
public void testStringArrayToStringArrayConversion() {
6684
String[] sourceTexts = { "textValue", "textValue2" };
67-
result = CustomBeanUtils.convertValue(sourceTexts, String[].class);
85+
Object result = CustomBeanUtils.convertValue(sourceTexts, String[].class);
6886
assertTrue(arraysMatch(sourceTexts, (String[]) result), "String array result does not match");
87+
}
6988

70-
// delimited string to string[]
89+
@Test
90+
public void testDelimitedStringToStringArrayConversion() {
7191
String sourceDelimited = "textValue,textValue2";
72-
result = CustomBeanUtils.convertValue(sourceDelimited, String[].class);
92+
String[] sourceTexts = { "textValue", "textValue2" };
93+
94+
Object result = CustomBeanUtils.convertValue(sourceDelimited, String[].class);
7395
assertTrue(arraysMatch(sourceTexts, (String[]) result), "Delimited string array result does not match");
96+
}
7497

75-
// integer[] to integer[]
98+
@Test
99+
public void testIntegerArrayToIntegerArrayConversion() {
76100
Integer[] sourceInts = { 123, 456 };
77-
result = CustomBeanUtils.convertValue(sourceInts, Integer[].class);
101+
Object result = CustomBeanUtils.convertValue(sourceInts, Integer[].class);
78102
assertTrue(arraysMatch(sourceInts, (Integer[]) result), "String array result does not match");
103+
}
79104

80-
// string[] to integer[]
105+
@Test
106+
public void testStringArrayToIntegerArrayConversion() {
81107
String[] sourceTextInts = { "123", "456" };
82-
result = CustomBeanUtils.convertValue(sourceTextInts, Integer[].class);
108+
Integer[] sourceInts = { 123, 456 };
109+
110+
Object result = CustomBeanUtils.convertValue(sourceTextInts, Integer[].class);
83111
assertTrue(arraysMatch(sourceInts, (Integer[]) result), "Integer string array result does not match");
112+
}
84113

85-
// delimited string to string[]
114+
@Test
115+
public void testDelimitedStringToIntegerArrayConversion() {
86116
String sourceDelimitedInts = "123,456";
87-
result = CustomBeanUtils.convertValue(sourceDelimitedInts, Integer[].class);
117+
Integer[] sourceInts = { 123, 456 };
118+
119+
Object result = CustomBeanUtils.convertValue(sourceDelimitedInts, Integer[].class);
88120
assertTrue(arraysMatch(sourceInts, (Integer[]) result), "Delimited integer array result does not match");
89121
}
90122

@@ -98,7 +130,6 @@ private boolean arraysMatch(Object[] array1, Object[] array2) {
98130
return false;
99131
}
100132
}
101-
102133
return true;
103134
}
104135
}

core/src/test/java/oracle/weblogic/deploy/json/JsonTranslatorTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.logging.Logger;
1111

1212
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.api.function.Executable;
1314

1415
import static java.nio.charset.StandardCharsets.UTF_8;
1516
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -29,8 +30,13 @@ public void testLexicalError() {
2930
// JSON { "abc": "xyz"\ } causes lexical error
3031
String text = "{ \"abc\": \"xyz\"/ }";
3132
InputStream stream = new ByteArrayInputStream(text.getBytes(UTF_8));
32-
JsonStreamTranslator translator = new JsonStreamTranslator("String", stream);
33-
assertThrows(JsonException.class, translator::parse, "Test must raise JsonException when model has a lexical error");
33+
final JsonStreamTranslator translator = new JsonStreamTranslator("String", stream);
34+
assertThrows(JsonException.class, new Executable() {
35+
@Override
36+
public void execute() throws Throwable {
37+
translator.parse();
38+
}
39+
}, "Test must raise JsonException when model has a lexical error");
3440

3541
logger.setLevel(originalLevel);
3642
}

0 commit comments

Comments
 (0)