1 30 31 package com.jgoodies.forms.layout; 32 33 import junit.framework.TestCase; 34 35 41 42 public final class FormLayoutGroupsTest extends TestCase { 43 44 private FormLayout layout; 45 46 49 protected void setUp() throws Exception { 50 super.setUp(); 51 layout = new FormLayout( 52 "pref, pref, pref, pref", 53 "pref, pref, pref, pref"); 54 } 55 56 59 protected void tearDown() throws Exception { 60 super.tearDown(); 61 layout = null; 62 } 63 64 68 public void testDeepCopyColumnGroups() { 69 int[][] columnGroups = createAllGroups(); 70 layout.setColumnGroups(columnGroups); 71 72 columnGroups[1] = new int[]{1, 4}; 74 if (equals(columnGroups, layout.getColumnGroups())) 75 fail("Column group sets should be immutable."); 76 77 columnGroups[0][0] = 5; 79 if (equals(columnGroups, layout.getColumnGroups())) 80 fail("Column groups should be immutable."); 81 } 82 83 84 88 public void testDeepCopyRowGroups() { 89 int[][] rowGroups = createAllGroups(); 90 layout.setRowGroups(rowGroups); 91 92 rowGroups[1] = new int[]{1, 4}; 94 if (equals(rowGroups, layout.getRowGroups())) 95 fail("The row group sets should be immutable."); 96 97 rowGroups[0][0] = 5; 99 if (equals(rowGroups, layout.getRowGroups())) 100 fail("Row groups should be immutable."); 101 } 102 103 106 public void testRejectInvalidColumnIndex() { 107 try { 108 layout.setColumnGroups(new int[][]{{1, 5}}); 109 fail("An invalid column index should be rejected."); 110 } catch (IndexOutOfBoundsException e) { 111 } 113 } 114 115 118 public void testRejectInvalidRowIndex() { 119 try { 120 layout.setRowGroups(new int[][]{{1, 5}}); 121 fail("An invalid row index should be rejected."); 122 } catch (IndexOutOfBoundsException e) { 123 } 125 } 126 127 130 public void testRejectDuplicateColumnIndex() { 131 try { 132 layout.setColumnGroups(new int[][]{{1, 2}, {2, 3}}); 133 fail("A duplicate column index should be rejected."); 134 } catch (IllegalArgumentException e) { 135 } 137 } 138 139 142 public void testRejectDuplicateRowIndex() { 143 try { 144 layout.setRowGroups(new int[][]{{1, 2}, {2, 3}}); 145 fail("A duplicate row index should be rejected."); 146 } catch (IllegalArgumentException e) { 147 } 149 } 150 151 152 154 private int[][] createAllGroups() { 155 int[] group1 = new int[]{1, 2}; 156 int[] group2 = new int[]{3, 4}; 157 return new int[][] {group1, group2}; 158 } 159 160 166 private boolean equals(int[][] array1, int[][] array2) { 167 if (array1.length != array2.length) 168 return false; 169 for (int i = 0; i < array1.length; i++) { 170 int[] subarray1 = array1[i]; 171 int[] subarray2 = array2[i]; 172 if (subarray1.length != subarray2.length) 173 return false; 174 for (int j = 0; j < subarray1.length; j++) { 175 if (subarray1[j] != subarray2[j]) 176 return false; 177 } 178 } 179 return true; 180 } 181 182 } | Popular Tags |