4 * Test the Byte object wrapper class.
6 * @author Brian Jones (cbj@gnu.org)
10 public static class constructorTest1
implements Test
14 public String
getName() {
18 public Result
test() {
20 Byte byteObject
= new Byte(b
);
21 } catch (Exception e
) {
22 return new Fail(e
.getMessage());
24 return new Fail(err
.getMessage());
30 public static class constructorTest2
implements Test
32 Byte byteObject
= null;
34 public String
getName() {
35 return "Byte(String)";
38 public Result
test() {
40 byteObject
= new Byte("1");
41 } catch (Exception e
) {
42 return new Fail(e
.getMessage());
44 return new Fail(err
.getMessage());
50 public static class byteValueTest
implements Test
52 public String
getName() {
53 return "Byte.byteValue()";
56 public Result
test() {
58 Byte byteObject
= new Byte(b
);
59 if (byteObject
.byteValue() == b
)
66 public static class decodeTest
implements Test
68 public String
getName() {
69 return "Byte.decode(String)";
72 public Result
test() {
73 Byte obj
= Byte
.decode("1");
74 if (obj
.byteValue() == 1)
81 public static class doubleValueTest
implements Test
83 public String
getName() {
84 return "Byte.doubleValue()";
87 public Result
test() {
90 Byte obj
= new Byte(b
);
91 if (obj
.doubleValue() == d
)
98 public static class equalsTest1
implements Test
100 public String
getName() {
101 return "Byte.equals(Object)";
104 public Result
test() {
105 Byte obj1
= null, obj2
= null;
106 obj1
= new Byte((byte)1);
107 obj2
= new Byte((byte)2);
108 if (obj1
.equals(obj2
))
109 return new Fail("1 != 2");
111 return new Pass("1 != 2");
115 public static class equalsTest2
implements Test
117 public String
getName() {
118 return "Byte.equals(Object)";
121 public Result
test() {
122 Byte obj1
= null, obj2
= null;
123 obj1
= new Byte((byte)1);
124 obj2
= new Byte((byte)2);
126 if (obj1
.equals(obj2
))
127 return new Pass("1 == 1");
129 return new Fail("1 == 1");
133 public static class floatValueTest
implements Test
135 public String
getName() {
136 return "Byte.floatValue()";
139 public Result
test() {
142 Byte obj
= new Byte(b
);
143 if (obj
.floatValue() == f
)
150 public static class hashCodeTest
implements Test
152 public String
getName() {
153 return "Byte.hashCode()";
156 public Result
test() {
157 boolean caught
= false;
158 Byte obj
= new Byte((byte)1);
159 int i
= obj
.hashCode();
163 return new Fail("hash is " + i
+ ". It should be 1.");
167 public static class intValueTest
implements Test
169 public String
getName() {
170 return "Byte.intValue()";
173 public Result
test() {
176 Byte obj
= new Byte(b
);
177 if (obj
.intValue() == i
)
184 public static class longValueTest
implements Test
186 public String
getName() {
187 return "Byte.longValue()";
190 public Result
test() {
193 Byte obj
= new Byte(b
);
194 if (obj
.longValue() == l
)
201 public static class parseByteTest1
implements Test
203 public String
getName() {
204 return "Byte.parseByte(String)";
207 public Result
test() {
208 byte b
= Byte
.parseByte("1");
216 public static class parseByteTest2
implements Test
218 public String
getName() {
219 return "Byte.parseByte(String, int)";
222 public Result
test() {
223 byte b
= Byte
.parseByte("-4", 10);
231 public static class shortValueTest
implements Test
233 public String
getName() {
234 return "Byte.shortValue()";
237 public Result
test() {
240 Byte obj
= new Byte(b
);
241 if (obj
.shortValue() == s
)
248 public static class toStringTest1
implements Test
250 public String
getName() {
251 return "Byte.toString()";
254 public Result
test() {
255 Byte obj
= new Byte((byte)-2);
256 String x
= obj
.toString();
264 public static class toStringTest2
implements Test
266 public String
getName() {
267 return "Byte.toString(byte)";
270 public Result
test() {
271 String x
= Byte
.toString((byte)-2);
279 public static class valueOfTest1
implements Test
281 public String
getName() {
282 return "Byte.valueOf(String, int)";
285 public Result
test() {
286 Byte obj1
= Byte
.valueOf("2",10);
287 Byte obj2
= new Byte((byte)2);
288 if (obj1
.intValue() == obj2
.intValue())
295 public static class valueOfTest2
implements Test
297 public String
getName() {
298 return "Byte.valueOf(String)";
301 public Result
test() {
302 Byte obj1
= Byte
.valueOf("2");
303 if (obj1
.intValue() == 2)
310 public static class variablesTest1
implements Test
312 public String
getName() {
313 return "Byte.MIN_VALUE";
316 public Result
test() {
317 byte min
= Byte
.MIN_VALUE
;
318 byte max
= Byte
.MAX_VALUE
;
320 if (min
== (byte)-128)
321 return new Pass("Byte.MIN_VALUE is -128");
323 return new Fail("Byte.MIN_VALUE is " + min
+ " != -128");
327 public static class variablesTest2
implements Test
329 public String
getName() {
330 return "Byte.MAX_VALUE";
333 public Result
test() {
334 byte min
= Byte
.MIN_VALUE
;
335 byte max
= Byte
.MAX_VALUE
;
337 if (max
== (byte)127)
338 return new Pass("Byte.MAX_VALUE is 127");
340 return new Fail("Byte.MAX_VALUE is " + max
+ " != 127");
344 public static class variablesTest3
implements Test
346 public String
getName() {
347 return "Byte.TYPE.getName()";
350 public Result
test() {
351 String x
= Byte
.TYPE
.getName();
352 if (x
.equals("byte") != true)
353 return new Fail("Byte.TYPE.getName() is " + x
+ " != byte");
355 return new Pass("Byte.TYPE.getName() is byte");
359 public static class typeInstance
implements Test
361 public String
getName() {
362 return "Byte.TYPE.newInstance()";
365 public Result
test() {
367 Object b
= Byte
.TYPE
.newInstance();
368 return new Fail("Byte.TYPE.newInstance succeeded.");
370 catch (InstantiationException e
) {
371 return new Pass("Byte.TYPE.newInstance failed with exception '" +
374 catch (Exception ex
) {
375 return new Fail("Byte.TYPE.newInstance threw incorrect exception '"
376 + ex
.toString() + "'");