mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
72 lines
2.0 KiB
Java
72 lines
2.0 KiB
Java
/*
|
|
* Copyright 2000-2009 JetBrains s.r.o.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
package com.intellij.util;
|
|
|
|
import com.intellij.util.ui.UIUtil;
|
|
import junit.framework.TestCase;
|
|
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.util.List;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
public class IJSwingUtilitiesTest extends TestCase {
|
|
private final JPanel myPanel = new JPanel();
|
|
|
|
public void testNoChildren() {
|
|
assertThat(getChildren()).isEmpty();
|
|
}
|
|
|
|
public void testOneLevel() {
|
|
MockComponent label1 = new MockComponent("1");
|
|
myPanel.add(label1);
|
|
MockComponent label2 = new MockComponent("2");
|
|
myPanel.add(label2);
|
|
assertThat(getChildren()).containsExactly(label1, label2);
|
|
}
|
|
|
|
public void testubTree() {
|
|
MockComponent label1 = new MockComponent("1");
|
|
MockComponent label2 = new MockComponent("2");
|
|
MockComponent label3 = new MockComponent("3");
|
|
MockComponent label4 = new MockComponent("4");
|
|
myPanel.add(label1);
|
|
JPanel subPanel = new JPanel();
|
|
myPanel.add(subPanel);
|
|
subPanel.add(label2);
|
|
subPanel.add(label3);
|
|
myPanel.add(label4);
|
|
assertThat(getChildren()).containsExactly(label1, subPanel, label2, label3, label4);
|
|
}
|
|
|
|
private List<Component> getChildren() {
|
|
return UIUtil.uiTraverser(myPanel).traverse().skip(1).toList();
|
|
}
|
|
|
|
private static class MockComponent extends JComponent {
|
|
private final String myName;
|
|
|
|
MockComponent(String name) {
|
|
myName = name;
|
|
}
|
|
|
|
public String toString() {
|
|
return myName;
|
|
}
|
|
}
|
|
}
|