Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package de.agilecoders.wicket.core.util;
 
 import org.junit.Test;
 
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

Tests the Attributes class

Author(s):
miha
public class AttributesTest extends WicketApplicationTest {
    @Test
    public void singleClassNameIsAddedToMarkup() {
        assertClassNamesPresent("classname");
    }
    @Test
    public void multipleClassNameIsAddedToMarkup() {
        startComponentInPage(createComponentWithCssClassNames("classname-a""classname-b"));
        assertClassNamesPresent("classname-a""classname-b");
    }
    @Test
    public void emptyClassNameIsIgnored() {
        assertThat(tester().getTagByWicketId(id()).getAttribute("class"), is(nullValue()));
    }
    @Test(expected = IllegalArgumentException.class)
    public void nullClassNameThrowsException() {
    }
    @Test
    public void removeClass() {
        ComponentTag tag = new ComponentTag("span"..);
        tag.put("class""class1 pull-right class2");
        Attributes.removeClass(tag"pull-right");
        assertThat(tag.getAttribute("class"), is(equalTo("class1 class2")));
    }

    
creates a new component with an onComponentTag method that adds given class names.

Parameters:
classNames class names to add
Returns:
new component
    private Component createComponentWithCssClassNames(final String... classNames) {
        WebMarkupContainer component = new WebMarkupContainer(id()) {
            @Override
            protected void onComponentTag(ComponentTag tag) {
                super.onComponentTag(tag);
                Attributes.addClass(tagclassNames);
            }
        };
        component.setOutputMarkupId(true);
        return component;
    }
New to GrepCode? Check out our FAQ X