001
002package com.ardor3d.extension.ui;
003
004import org.junit.Assert;
005import org.junit.Before;
006import org.junit.Test;
007
008public class UIComponentTest {
009
010    private UIComponent component;
011
012    @Before
013    public void setUp() throws Exception {
014        component = new UIComponent() {
015
016        };
017    }
018
019    @Test
020    public void minimumSizeSetsContentSize() throws Exception {
021        final int contentHeight = component.getContentHeight();
022        final int contentWidth = component.getContentWidth();
023        Assert.assertTrue(contentHeight < 200);
024        Assert.assertTrue(contentWidth < 100);
025        component.setMinimumContentSize(100, 200);
026        Assert.assertEquals(100, component.getMinimumLocalComponentWidth());
027        Assert.assertEquals(200, component.getMinimumLocalComponentHeight());
028        Assert.assertEquals(100, component.getContentWidth());
029        Assert.assertEquals(200, component.getContentHeight());
030    }
031
032    @Test
033    public void cantSetContentSizeSmallerThanMinimum() throws Exception {
034        final int minWidth = component.getMinimumLocalComponentWidth();
035        final int minHeight = component.getMinimumLocalComponentHeight();
036
037        final int contentHeight = component.getContentHeight();
038        final int contentWidth = component.getContentWidth();
039        Assert.assertTrue(contentWidth >= minWidth);
040        Assert.assertTrue(contentHeight >= minHeight);
041
042        component.setContentSize(minWidth - 2, minHeight - 1);
043
044        Assert.assertEquals(minWidth, component.getContentWidth());
045        Assert.assertEquals(minHeight, component.getContentHeight());
046    }
047
048    @Test
049    public void cantSetContentSizeLargerThanMaximum() throws Exception {
050        final int maxWidth = component.getMaximumLocalComponentWidth();
051        final int maxHeight = component.getMaximumLocalComponentHeight();
052
053        final int contentHeight = component.getContentHeight();
054        final int contentWidth = component.getContentWidth();
055        Assert.assertTrue(contentWidth <= maxWidth);
056        Assert.assertTrue(contentHeight <= maxHeight);
057
058        component.setContentSize(maxWidth + 2, maxHeight + 3);
059
060        Assert.assertEquals(maxWidth, component.getContentWidth());
061        Assert.assertEquals(maxHeight, component.getContentHeight());
062    }
063
064}