001    package serp.bytecode;
002    
003    import junit.framework.*;
004    import junit.textui.*;
005    
006    /**
007     * Tests the handling of array {@link BCClass}es.
008     *
009     * @author Abe White
010     */
011    public class TestArray extends AbstractStateTest {
012        private BCClass _bc2 = null;
013    
014        public TestArray(String test) {
015            super(test);
016        }
017    
018        public void setUp() {
019            _bc = _project.loadClass(String[].class);
020            _bc2 = _project.loadClass(int[][].class);
021        }
022    
023        public void testType() {
024            assertEquals(String[].class.getName(), _bc.getName());
025            assertEquals("java.lang", _bc.getPackageName());
026            assertEquals("String[]", _bc.getClassName());
027            assertEquals(String[].class, _bc.getType());
028    
029            try {
030                _bc.setName("Foo[]");
031                fail("Allowed set name");
032            } catch (UnsupportedOperationException uoe) {
033            }
034    
035            assertTrue(!_bc.isPrimitive());
036            assertTrue(_bc.isArray());
037    
038            assertEquals(int[][].class.getName(), _bc2.getName());
039            assertNull(_bc2.getPackageName());
040            assertEquals("int[][]", _bc2.getClassName());
041            assertEquals(int[][].class, _bc2.getType());
042        }
043    
044        public void testSuperclass() {
045            assertEquals(Object.class.getName(), _bc.getSuperclassName());
046            try {
047                _bc.setSuperclass("Foo");
048                fail("Allowed set superclass");
049            } catch (UnsupportedOperationException uoe) {
050            }
051        }
052    
053        public void testComponent() {
054            assertEquals(String.class.getName(), _bc.getComponentName());
055            assertEquals(String.class, _bc.getComponentType());
056            assertEquals(String.class, _bc.getComponentBC().getType());
057            assertEquals(int[].class.getName(), _bc2.getComponentName());
058            assertEquals(int[].class, _bc2.getComponentType());
059            assertEquals(int[].class, _bc2.getComponentBC().getType());
060        }
061    
062        public static Test suite() {
063            return new TestSuite(TestArray.class);
064        }
065    
066        public static void main(String[] args) {
067            TestRunner.run(suite());
068        }
069    }