BuddySupport { public static void removeAll(JTextField textField) { List<Component> left = buddies(Position.LEFT, textField); for (Component c : left) { textField.remove(c); } left.clear(); List<Component> right = buddies(Position.RIGHT, textField); for (Component c : right) { textField.remove(c); } right.clear(); }  static void addLeft(Component c, JTextField textField); static void addRight(Component c, JTextField textField); static void add(Component c, Position pos, JTextField textField); static void addGap(int width, Position pos, JTextField textField); static void setRight(JTextField textField, List<Component> rightBuddies); static void setLeft(JTextField textField, List<Component> leftBuddies); static void set(List<Component> buddies, Position pos, JTextField textField); static List<Component> getLeft(JTextField textField); static List<Component> getRight(JTextField textField); static List<Component> getBuddies(Position pos, JTextField textField); static boolean isBuddy(Component c, JTextField textField); static void remove(JComponent c, JTextField textField); static void removeAll(JTextField textField); static void setOuterMargin(JTextField buddyField, Insets margin); static Insets getOuterMargin(JTextField buddyField); static void ensureBuddiesAreInComponentHierarchy(JTextField textField); static Component createGap(int width); static final String OUTER_MARGIN; }
@Test public void testRemoveAll() throws Exception { JButton button1 = new JButton(); JButton button2 = new JButton(); BuddySupport.addLeft(button1, tf); BuddySupport.addRight(button2, tf); BuddySupport.removeAll(tf); Assert.assertSame(0, BuddySupport.getLeft(tf).size()); Assert.assertSame(0, BuddySupport.getRight(tf).size()); Assert.assertSame(0, tf.getComponentCount()); }