com.googlecode.gwt.test.assertions.BasePanelAssert Maven / Gradle / Ivy
package com.googlecode.gwt.test.assertions;
import com.google.gwt.user.client.ui.*;
import java.util.Iterator;
import static org.assertj.core.util.Objects.areEqual;
/**
* Base class for all {@link Panel} assertions.
*
* @param used to simulate "self types." For more information please read "Emulating 'self types' using Java Generics to simplify fluent API
* implementation."
* @param the type of the "actual" value.
* @author Gael Lazzari
*/
public class BasePanelAssert, A extends Panel> extends
BaseWidgetAssert {
/**
* Creates a new {@link BasePanelAssert}
.
*
* @param actual the actual value to verify.
* @param selfType the "self type."
*/
protected BasePanelAssert(A actual, Class selfType) {
super(actual, selfType);
}
/**
* Verifies that the actual {@link ComplexPanel} child widget count is equal to the given one.
*
* @param expected the expected widget count.
* @return this assertion object.
* @throws AssertionError if the actual widget count is not equal to the given one.
* @see ComplexPanel#getWidgetCount()
*/
public S widgetCountEquals(int expected) {
int widgetCount = getWigetCount(actual);
if (areEqual(widgetCount, expected))
return myself;
throw propertyComparisonFailed("WidgetCount", widgetCount, expected);
}
private int getWigetCount(A actual) {
if (actual instanceof IndexedPanel) {
return ((IndexedPanel) actual).getWidgetCount();
} else if (actual instanceof SimplePanel) {
return 1;
}
Iterator it = actual.iterator();
int count = 0;
while (it.hasNext()) {
count++;
it.next();
}
return count;
}
}