1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements.  See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License.  You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.apache.harmony.luni.tests.java.lang;
18
19import dalvik.annotation.TestTargets;
20import dalvik.annotation.TestLevel;
21import dalvik.annotation.TestTargetNew;
22import dalvik.annotation.TestTargetClass;
23
24import junit.framework.TestCase;
25
26@TestTargetClass(Short.class)
27public class ShortTest extends TestCase {
28    private Short sp = new Short((short) 18000);
29    private Short sn = new Short((short) -19000);
30
31    /**
32     * @tests java.lang.Short#byteValue()
33     */
34    @TestTargetNew(
35        level = TestLevel.PARTIAL_COMPLETE,
36        notes = "Checks boundary values.",
37        method = "byteValue",
38        args = {}
39    )
40    public void test_byteValue() {
41        // Test for method byte java.lang.Short.byteValue()
42        assertEquals("Returned incorrect byte value", 0, new Short(Short.MIN_VALUE)
43                .byteValue());
44        assertEquals("Returned incorrect byte value", -1, new Short(Short.MAX_VALUE)
45                .byteValue());
46    }
47
48    /**
49     * @tests java.lang.Short#compareTo(java.lang.Short)
50     */
51    @TestTargetNew(
52        level = TestLevel.COMPLETE,
53        notes = "",
54        method = "compareTo",
55        args = {java.lang.Short.class}
56    )
57    public void test_compareToLjava_lang_Short() {
58        // Test for method int java.lang.Short.compareTo(java.lang.Short)
59        Short s = new Short((short) 1);
60        Short x = new Short((short) 3);
61        assertTrue(
62                "Should have returned negative value when compared to greater short",
63                s.compareTo(x) < 0);
64        x = new Short((short) -1);
65        assertTrue(
66                "Should have returned positive value when compared to lesser short",
67                s.compareTo(x) > 0);
68        x = new Short((short) 1);
69        assertEquals("Should have returned zero when compared to equal short",
70                             0, s.compareTo(x));
71
72        try {
73            new Short((short)0).compareTo(null);
74            fail("No NPE");
75        } catch (NullPointerException e) {
76        }
77    }
78
79    /**
80     * @tests java.lang.Short#decode(java.lang.String)
81     */
82    @TestTargetNew(
83        level = TestLevel.PARTIAL,
84        notes = "Doesn't check that no whitespace characters are permitted in the String. ",
85        method = "decode",
86        args = {java.lang.String.class}
87    )
88    public void test_decodeLjava_lang_String2() {
89        // Test for method java.lang.Short
90        // java.lang.Short.decode(java.lang.String)
91        assertTrue("Did not decode -1 correctly", Short.decode("-1")
92                .shortValue() == (short) -1);
93        assertTrue("Did not decode -100 correctly", Short.decode("-100")
94                .shortValue() == (short) -100);
95        assertTrue("Did not decode 23 correctly", Short.decode("23")
96                .shortValue() == (short) 23);
97        assertTrue("Did not decode 0x10 correctly", Short.decode("0x10")
98                .shortValue() == (short) 16);
99        assertTrue("Did not decode 32767 correctly", Short.decode("32767")
100                .shortValue() == (short) 32767);
101        assertTrue("Did not decode -32767 correctly", Short.decode("-32767")
102                .shortValue() == (short) -32767);
103        assertTrue("Did not decode -32768 correctly", Short.decode("-32768")
104                .shortValue() == (short) -32768);
105
106        boolean exception = false;
107        try {
108            Short.decode("123s");
109        } catch (NumberFormatException e) {
110            // correct
111            exception = true;
112        }
113        assertTrue("Did not throw NumberFormatException decoding 123s",
114                exception);
115
116        exception = false;
117        try {
118            Short.decode("32768");
119        } catch (NumberFormatException e) {
120            // Correct
121            exception = true;
122        }
123        assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
124
125        exception = false;
126        try {
127            Short.decode("-32769");
128        } catch (NumberFormatException e) {
129            // Correct
130            exception = true;
131        }
132        assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
133
134        exception = false;
135        try {
136            Short.decode("0x8000");
137        } catch (NumberFormatException e) {
138            // Correct
139            exception = true;
140        }
141        assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
142
143        exception = false;
144        try {
145            Short.decode("-0x8001");
146        } catch (NumberFormatException e) {
147            // Correct
148            exception = true;
149        }
150        assertTrue("Failed to throw exception for hex MIN_VALUE - 1", exception);
151    }
152
153    /**
154     * @tests java.lang.Short#parseShort(java.lang.String)
155     */
156    @TestTargetNew(
157        level = TestLevel.COMPLETE,
158        notes = "",
159        method = "parseShort",
160        args = {java.lang.String.class}
161    )
162    public void test_parseShortLjava_lang_String2() {
163        // Test for method short java.lang.Short.parseShort(java.lang.String)
164        short sp = Short.parseShort("32746");
165        short sn = Short.parseShort("-32746");
166
167        assertTrue("Incorrect parse of short", sp == (short) 32746
168                && (sn == (short) -32746));
169        assertEquals("Returned incorrect value for 0", 0, Short.parseShort("0"));
170        assertTrue("Returned incorrect value for most negative value", Short
171                .parseShort("-32768") == (short) 0x8000);
172        assertTrue("Returned incorrect value for most positive value", Short
173                .parseShort("32767") == 0x7fff);
174
175        boolean exception = false;
176        try {
177            Short.parseShort("32768");
178        } catch (NumberFormatException e) {
179            // Correct
180            exception = true;
181        }
182        assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
183
184        exception = false;
185        try {
186            Short.parseShort("-32769");
187        } catch (NumberFormatException e) {
188            // Correct
189            exception = true;
190        }
191        assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
192    }
193
194    /**
195     * @tests java.lang.Short#parseShort(java.lang.String, int)
196     */
197    @TestTargetNew(
198        level = TestLevel.COMPLETE,
199        notes = "",
200        method = "parseShort",
201        args = {java.lang.String.class, int.class}
202    )
203    public void test_parseShortLjava_lang_StringI2() {
204        // Test for method short java.lang.Short.parseShort(java.lang.String,
205        // int)
206        boolean aThrow = true;
207        assertEquals("Incorrectly parsed hex string",
208                255, Short.parseShort("FF", 16));
209        assertEquals("Incorrectly parsed oct string",
210                16, Short.parseShort("20", 8));
211        assertEquals("Incorrectly parsed dec string",
212                20, Short.parseShort("20", 10));
213        assertEquals("Incorrectly parsed bin string",
214                4, Short.parseShort("100", 2));
215        assertEquals("Incorrectly parsed -hex string", -255, Short
216                .parseShort("-FF", 16));
217        assertEquals("Incorrectly parsed -oct string",
218                -16, Short.parseShort("-20", 8));
219        assertEquals("Incorrectly parsed -bin string", -4, Short
220                .parseShort("-100", 2));
221        assertEquals("Returned incorrect value for 0 hex", 0, Short.parseShort("0",
222                16));
223        assertTrue("Returned incorrect value for most negative value hex",
224                Short.parseShort("-8000", 16) == (short) 0x8000);
225        assertTrue("Returned incorrect value for most positive value hex",
226                Short.parseShort("7fff", 16) == 0x7fff);
227        assertEquals("Returned incorrect value for 0 decimal", 0, Short.parseShort(
228                "0", 10));
229        assertTrue("Returned incorrect value for most negative value decimal",
230                Short.parseShort("-32768", 10) == (short) 0x8000);
231        assertTrue("Returned incorrect value for most positive value decimal",
232                Short.parseShort("32767", 10) == 0x7fff);
233
234        try {
235            Short.parseShort("FF", 2);
236        } catch (NumberFormatException e) {
237            // Correct
238            aThrow = false;
239        }
240        if (aThrow) {
241            fail(
242                    "Failed to throw exception when passed hex string and base 2 radix");
243        }
244
245        boolean exception = false;
246        try {
247            Short.parseShort("10000000000", 10);
248        } catch (NumberFormatException e) {
249            // Correct
250            exception = true;
251        }
252        assertTrue(
253                "Failed to throw exception when passed string larger than 16 bits",
254                exception);
255
256        exception = false;
257        try {
258            Short.parseShort("32768", 10);
259        } catch (NumberFormatException e) {
260            // Correct
261            exception = true;
262        }
263        assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
264
265        exception = false;
266        try {
267            Short.parseShort("-32769", 10);
268        } catch (NumberFormatException e) {
269            // Correct
270            exception = true;
271        }
272        assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
273
274        exception = false;
275        try {
276            Short.parseShort("8000", 16);
277        } catch (NumberFormatException e) {
278            // Correct
279            exception = true;
280        }
281        assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
282
283        exception = false;
284        try {
285            Short.parseShort("-8001", 16);
286        } catch (NumberFormatException e) {
287            // Correct
288            exception = true;
289        }
290        assertTrue("Failed to throw exception for hex MIN_VALUE + 1", exception);
291    }
292
293    /**
294     * @tests java.lang.Short#toString()
295     */
296    @TestTargetNew(
297        level = TestLevel.COMPLETE,
298        notes = "",
299        method = "toString",
300        args = {}
301    )
302    public void test_toString2() {
303        // Test for method java.lang.String java.lang.Short.toString()
304        assertTrue("Invalid string returned", sp.toString().equals("18000")
305                && (sn.toString().equals("-19000")));
306        assertEquals("Returned incorrect string", "32767", new Short((short) 32767)
307                .toString());
308        assertEquals("Returned incorrect string", "-32767", new Short((short) -32767)
309                .toString());
310        assertEquals("Returned incorrect string", "-32768", new Short((short) -32768)
311                .toString());
312    }
313
314    /**
315     * @tests java.lang.Short#toString(short)
316     */
317    @TestTargetNew(
318        level = TestLevel.PARTIAL_COMPLETE,
319        notes = "",
320        method = "toString",
321        args = {short.class}
322    )
323    public void test_toStringS2() {
324        // Test for method java.lang.String java.lang.Short.toString(short)
325        assertEquals("Returned incorrect string", "32767", Short.toString((short) 32767)
326                );
327        assertEquals("Returned incorrect string", "-32767", Short.toString((short) -32767)
328                );
329        assertEquals("Returned incorrect string", "-32768", Short.toString((short) -32768)
330                );
331    }
332
333    /**
334     * @tests java.lang.Short#valueOf(java.lang.String)
335     */
336    @TestTargetNew(
337        level = TestLevel.PARTIAL_COMPLETE,
338        notes = "Checks boundary values.",
339        method = "valueOf",
340        args = {java.lang.String.class}
341    )
342    public void test_valueOfLjava_lang_String2() {
343        // Test for method java.lang.Short
344        // java.lang.Short.valueOf(java.lang.String)
345        assertEquals("Returned incorrect short", -32768, Short.valueOf("-32768")
346                .shortValue());
347        assertEquals("Returned incorrect short", 32767, Short.valueOf("32767")
348                .shortValue());
349    }
350
351    /**
352     * @tests java.lang.Short#valueOf(java.lang.String, int)
353     */
354    @TestTargetNew(
355        level = TestLevel.COMPLETE,
356        notes = "",
357        method = "valueOf",
358        args = {java.lang.String.class, int.class}
359    )
360    public void test_valueOfLjava_lang_StringI2() {
361        // Test for method java.lang.Short
362        // java.lang.Short.valueOf(java.lang.String, int)
363        boolean aThrow = true;
364        assertEquals("Incorrectly parsed hex string", 255, Short.valueOf("FF", 16)
365                .shortValue());
366        assertEquals("Incorrectly parsed oct string", 16, Short.valueOf("20", 8)
367                .shortValue());
368        assertEquals("Incorrectly parsed dec string", 20, Short.valueOf("20", 10)
369                .shortValue());
370        assertEquals("Incorrectly parsed bin string", 4, Short.valueOf("100", 2)
371                .shortValue());
372        assertEquals("Incorrectly parsed -hex string", -255, Short.valueOf("-FF", 16)
373                .shortValue());
374        assertEquals("Incorrectly parsed -oct string", -16, Short.valueOf("-20", 8)
375                .shortValue());
376        assertEquals("Incorrectly parsed -bin string", -4, Short.valueOf("-100", 2)
377                .shortValue());
378        assertTrue("Did not decode 32767 correctly", Short.valueOf("32767", 10)
379                .shortValue() == (short) 32767);
380        assertTrue("Did not decode -32767 correctly", Short.valueOf("-32767",
381                10).shortValue() == (short) -32767);
382        assertTrue("Did not decode -32768 correctly", Short.valueOf("-32768",
383                10).shortValue() == (short) -32768);
384        try {
385            Short.valueOf("FF", 2);
386        } catch (NumberFormatException e) {
387            // Correct
388            aThrow = false;
389        }
390        if (aThrow) {
391            fail(
392                    "Failed to throw exception when passed hex string and base 2 radix");
393        }
394        try {
395            Short.valueOf("10000000000", 10);
396        } catch (NumberFormatException e) {
397            // Correct
398            return;
399        }
400        fail(
401                "Failed to throw exception when passed string larger than 16 bits");
402    }
403    /**
404     * @tests java.lang.Short#valueOf(short)
405     */
406    @TestTargetNew(
407        level = TestLevel.COMPLETE,
408        notes = "",
409        method = "valueOf",
410        args = {short.class}
411    )
412    public void test_valueOfS() {
413        assertEquals(new Short(Short.MIN_VALUE), Short.valueOf(Short.MIN_VALUE));
414        assertEquals(new Short(Short.MAX_VALUE), Short.valueOf(Short.MAX_VALUE));
415        assertEquals(new Short((short) 0), Short.valueOf((short) 0));
416
417        short s = -128;
418        while (s < 128) {
419            assertEquals(new Short(s), Short.valueOf(s));
420            assertSame(Short.valueOf(s), Short.valueOf(s));
421            s++;
422        }
423    }
424
425    /**
426     * @tests java.lang.Short#hashCode()
427     */
428    @TestTargetNew(
429        level = TestLevel.COMPLETE,
430        notes = "",
431        method = "hashCode",
432        args = {}
433    )
434    public void test_hashCode() {
435        assertEquals(1, new Short((short)1).hashCode());
436        assertEquals(2, new Short((short)2).hashCode());
437        assertEquals(0, new Short((short)0).hashCode());
438        assertEquals(-1, new Short((short)-1).hashCode());
439    }
440
441    /**
442     * @tests java.lang.Short#Short(String)
443     */
444    @TestTargetNew(
445        level = TestLevel.COMPLETE,
446        notes = "",
447        method = "Short",
448        args = {java.lang.String.class}
449    )
450    public void test_ConstructorLjava_lang_String() {
451        assertEquals(new Short((short)0), new Short("0"));
452        assertEquals(new Short((short)1), new Short("1"));
453        assertEquals(new Short((short)-1), new Short("-1"));
454
455        try {
456            new Short("0x1");
457            fail("Expected NumberFormatException with hex string.");
458        } catch (NumberFormatException e) {}
459
460        try {
461            new Short("9.2");
462            fail("Expected NumberFormatException with floating point string.");
463        } catch (NumberFormatException e) {}
464
465        try {
466            new Short("");
467            fail("Expected NumberFormatException with empty string.");
468        } catch (NumberFormatException e) {}
469
470        try {
471            new Short(null);
472            fail("Expected NumberFormatException with null string.");
473        } catch (NumberFormatException e) {}
474    }
475
476    /**
477     * @tests java.lang.Short#Short(short)
478     */
479    @TestTargetNew(
480        level = TestLevel.COMPLETE,
481        notes = "",
482        method = "Short",
483        args = {short.class}
484    )
485    public void test_ConstructorS() {
486        assertEquals(1, new Short((short)1).shortValue());
487        assertEquals(2, new Short((short)2).shortValue());
488        assertEquals(0, new Short((short)0).shortValue());
489        assertEquals(-1, new Short((short)-1).shortValue());
490    }
491
492    /**
493     * @tests java.lang.Short#byteValue()
494     */
495    @TestTargetNew(
496        level = TestLevel.PARTIAL_COMPLETE,
497        notes = "Doesn't check boundary values.",
498        method = "byteValue",
499        args = {}
500    )
501    public void test_byteValue1() {
502        assertEquals(1, new Short((short)1).byteValue());
503        assertEquals(2, new Short((short)2).byteValue());
504        assertEquals(0, new Short((short)0).byteValue());
505        assertEquals(-1, new Short((short)-1).byteValue());
506    }
507
508    /**
509     * @tests java.lang.Short#equals(Object)
510     */
511    @TestTargetNew(
512        level = TestLevel.COMPLETE,
513        notes = "",
514        method = "equals",
515        args = {java.lang.Object.class}
516    )
517    public void test_equalsLjava_lang_Object() {
518        assertEquals(new Short((short)0), Short.valueOf((short)0));
519        assertEquals(new Short((short)1), Short.valueOf((short)1));
520        assertEquals(new Short((short)-1), Short.valueOf((short)-1));
521
522        Short fixture = new Short((short)25);
523        assertEquals(fixture, fixture);
524        assertFalse(fixture.equals(null));
525        assertFalse(fixture.equals("Not a Short"));
526    }
527
528    /**
529     * @tests java.lang.Short#toString()
530     */
531    @TestTargetNew(
532        level = TestLevel.COMPLETE,
533        notes = "",
534        method = "toString",
535        args = {}
536    )
537    public void test_toString() {
538        assertEquals("-1", new Short((short)-1).toString());
539        assertEquals("0", new Short((short)0).toString());
540        assertEquals("1", new Short((short)1).toString());
541        assertEquals("-1", new Short((short)0xFFFF).toString());
542    }
543
544    /**
545     * @tests java.lang.Short#toString(short)
546     */
547    @TestTargetNew(
548        level = TestLevel.PARTIAL_COMPLETE,
549        notes = "",
550        method = "toString",
551        args = {short.class}
552    )
553    public void test_toStringS() {
554        assertEquals("-1", Short.toString((short)-1));
555        assertEquals("0", Short.toString((short)0));
556        assertEquals("1", Short.toString((short)1));
557        assertEquals("-1", Short.toString((short)0xFFFF));
558    }
559
560    /**
561     * @tests java.lang.Short#valueOf(String)
562     */
563    @TestTargetNew(
564        level = TestLevel.PARTIAL_COMPLETE,
565        notes = "Doesn't check boundary values.",
566        method = "valueOf",
567        args = {java.lang.String.class}
568    )
569    public void test_valueOfLjava_lang_String() {
570        assertEquals(new Short((short)0), Short.valueOf("0"));
571        assertEquals(new Short((short)1), Short.valueOf("1"));
572        assertEquals(new Short((short)-1), Short.valueOf("-1"));
573
574        try {
575            Short.valueOf("0x1");
576            fail("Expected NumberFormatException with hex string.");
577        } catch (NumberFormatException e) {}
578
579        try {
580            Short.valueOf("9.2");
581            fail("Expected NumberFormatException with floating point string.");
582        } catch (NumberFormatException e) {}
583
584        try {
585            Short.valueOf("");
586            fail("Expected NumberFormatException with empty string.");
587        } catch (NumberFormatException e) {}
588
589        try {
590            Short.valueOf(null);
591            fail("Expected NumberFormatException with null string.");
592        } catch (NumberFormatException e) {}
593    }
594
595    /**
596     * @tests java.lang.Short#valueOf(String,int)
597     */
598    @TestTargetNew(
599        level = TestLevel.COMPLETE,
600        notes = "",
601        method = "valueOf",
602        args = {java.lang.String.class, int.class}
603    )
604    public void test_valueOfLjava_lang_StringI() {
605        assertEquals(new Short((short)0), Short.valueOf("0", 10));
606        assertEquals(new Short((short)1), Short.valueOf("1", 10));
607        assertEquals(new Short((short)-1), Short.valueOf("-1", 10));
608
609        //must be consistent with Character.digit()
610        assertEquals(Character.digit('1', 2), Short.valueOf("1", 2).byteValue());
611        assertEquals(Character.digit('F', 16), Short.valueOf("F", 16).byteValue());
612
613        try {
614            Short.valueOf("0x1", 10);
615            fail("Expected NumberFormatException with hex string.");
616        } catch (NumberFormatException e) {}
617
618        try {
619            Short.valueOf("9.2", 10);
620            fail("Expected NumberFormatException with floating point string.");
621        } catch (NumberFormatException e) {}
622
623        try {
624            Short.valueOf("", 10);
625            fail("Expected NumberFormatException with empty string.");
626        } catch (NumberFormatException e) {}
627
628        try {
629            Short.valueOf(null, 10);
630            fail("Expected NumberFormatException with null string.");
631        } catch (NumberFormatException e) {}
632    }
633
634    /**
635     * @tests java.lang.Short#parseShort(String)
636     */
637    @TestTargetNew(
638        level = TestLevel.PARTIAL,
639        notes = "Doesn't check boundary values, unicodes.",
640        method = "parseShort",
641        args = {java.lang.String.class}
642    )
643    public void test_parseShortLjava_lang_String() {
644        assertEquals(0, Short.parseShort("0"));
645        assertEquals(1, Short.parseShort("1"));
646        assertEquals(-1, Short.parseShort("-1"));
647
648        try {
649            Short.parseShort("0x1");
650            fail("Expected NumberFormatException with hex string.");
651        } catch (NumberFormatException e) {}
652
653        try {
654            Short.parseShort("9.2");
655            fail("Expected NumberFormatException with floating point string.");
656        } catch (NumberFormatException e) {}
657
658        try {
659            Short.parseShort("");
660            fail("Expected NumberFormatException with empty string.");
661        } catch (NumberFormatException e) {}
662
663        try {
664            Short.parseShort(null);
665            fail("Expected NumberFormatException with null string.");
666        } catch (NumberFormatException e) {}
667    }
668
669    /**
670     * @tests java.lang.Short#parseShort(String,int)
671     */
672    @TestTargetNew(
673        level = TestLevel.PARTIAL,
674        notes = "Doesn't check boundary values.",
675        method = "parseShort",
676        args = {java.lang.String.class, int.class}
677    )
678    public void test_parseShortLjava_lang_StringI() {
679        assertEquals(0, Short.parseShort("0", 10));
680        assertEquals(1, Short.parseShort("1", 10));
681        assertEquals(-1, Short.parseShort("-1", 10));
682
683        //must be consistent with Character.digit()
684        assertEquals(Character.digit('1', 2), Short.parseShort("1", 2));
685        assertEquals(Character.digit('F', 16), Short.parseShort("F", 16));
686
687        try {
688            Short.parseShort("0x1", 10);
689            fail("Expected NumberFormatException with hex string.");
690        } catch (NumberFormatException e) {}
691
692        try {
693            Short.parseShort("9.2", 10);
694            fail("Expected NumberFormatException with floating point string.");
695        } catch (NumberFormatException e) {}
696
697        try {
698            Short.parseShort("", 10);
699            fail("Expected NumberFormatException with empty string.");
700        } catch (NumberFormatException e) {}
701
702        try {
703            Short.parseShort(null, 10);
704            fail("Expected NumberFormatException with null string.");
705        } catch (NumberFormatException e) {}
706    }
707
708    /**
709     * @tests java.lang.Short#decode(String)
710     */
711    @TestTargetNew(
712        level = TestLevel.COMPLETE,
713        notes = "",
714        method = "decode",
715        args = {java.lang.String.class}
716    )
717    public void test_decodeLjava_lang_String() {
718        assertEquals(new Short((short)0), Short.decode("0"));
719        assertEquals(new Short((short)1), Short.decode("1"));
720        assertEquals(new Short((short)-1), Short.decode("-1"));
721        assertEquals(new Short((short)0xF), Short.decode("0xF"));
722        assertEquals(new Short((short)0xF), Short.decode("#F"));
723        assertEquals(new Short((short)0xF), Short.decode("0XF"));
724        assertEquals(new Short((short)07), Short.decode("07"));
725
726        try {
727            Short.decode(" 0 ");
728            fail("NumberFormatException is not thrown.");
729        } catch(NumberFormatException nfe) {
730            //expected
731        }
732
733        try {
734            Short.decode("9.2");
735            fail("Expected NumberFormatException with floating point string.");
736        } catch (NumberFormatException e) {}
737
738        try {
739            Short.decode("");
740            fail("Expected NumberFormatException with empty string.");
741        } catch (NumberFormatException e) {}
742
743        try {
744            Short.decode(null);
745            //undocumented NPE, but seems consistent across JREs
746            fail("Expected NullPointerException with null string.");
747        } catch (NullPointerException e) {}
748    }
749
750    /**
751     * @tests java.lang.Short#doubleValue()
752     */
753    @TestTargetNew(
754        level = TestLevel.COMPLETE,
755        notes = "",
756        method = "doubleValue",
757        args = {}
758    )
759    public void test_doubleValue() {
760        assertEquals(-1D, new Short((short)-1).doubleValue(), 0D);
761        assertEquals(0D, new Short((short)0).doubleValue(), 0D);
762        assertEquals(1D, new Short((short)1).doubleValue(), 0D);
763    }
764
765    /**
766     * @tests java.lang.Short#floatValue()
767     */
768    @TestTargetNew(
769        level = TestLevel.COMPLETE,
770        notes = "",
771        method = "floatValue",
772        args = {}
773    )
774    public void test_floatValue() {
775        assertEquals(-1F, new Short((short)-1).floatValue(), 0F);
776        assertEquals(0F, new Short((short)0).floatValue(), 0F);
777        assertEquals(1F, new Short((short)1).floatValue(), 0F);
778    }
779
780    /**
781     * @tests java.lang.Short#intValue()
782     */
783    @TestTargetNew(
784        level = TestLevel.COMPLETE,
785        notes = "",
786        method = "intValue",
787        args = {}
788    )
789    public void test_intValue() {
790        assertEquals(-1, new Short((short)-1).intValue());
791        assertEquals(0, new Short((short)0).intValue());
792        assertEquals(1, new Short((short)1).intValue());
793    }
794
795    /**
796     * @tests java.lang.Short#longValue()
797     */
798    @TestTargetNew(
799        level = TestLevel.COMPLETE,
800        notes = "",
801        method = "longValue",
802        args = {}
803    )
804    public void test_longValue() {
805        assertEquals(-1L, new Short((short)-1).longValue());
806        assertEquals(0L, new Short((short)0).longValue());
807        assertEquals(1L, new Short((short)1).longValue());
808    }
809
810    /**
811     * @tests java.lang.Short#shortValue()
812     */
813    @TestTargetNew(
814        level = TestLevel.COMPLETE,
815        notes = "",
816        method = "shortValue",
817        args = {}
818    )
819    public void test_shortValue() {
820        assertEquals(-1, new Short((short)-1).shortValue());
821        assertEquals(0, new Short((short)0).shortValue());
822        assertEquals(1, new Short((short)1).shortValue());
823    }
824
825    /**
826     * @tests java.lang.Short#reverseBytes(short)
827     */
828    @TestTargetNew(
829        level = TestLevel.COMPLETE,
830        notes = "",
831        method = "reverseBytes",
832        args = {short.class}
833    )
834    public void test_reverseBytesS() {
835        assertEquals((short)0xABCD, Short.reverseBytes((short)0xCDAB));
836        assertEquals((short)0x1234, Short.reverseBytes((short)0x3412));
837        assertEquals((short)0x0011, Short.reverseBytes((short)0x1100));
838        assertEquals((short)0x2002, Short.reverseBytes((short)0x0220));
839    }
840
841}
842