Skip to content

Commit

Permalink
Fix CI failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
handreyrc committed Mar 12, 2024
1 parent c2b9aa8 commit fad41bf
Showing 1 changed file with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,61 +20,52 @@

package org.kie.workbench.common.stunner.core.client.shape.impl;

import java.util.function.Function;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.workbench.common.stunner.core.client.shape.ShapeState;
import org.kie.workbench.common.stunner.core.client.theme.StunnerColorTheme;
import org.kie.workbench.common.stunner.core.client.theme.StunnerTheme;
import org.mockito.junit.MockitoJUnitRunner;

import static org.junit.Assert.assertEquals;
import static org.kie.workbench.common.stunner.core.client.shape.ShapeState.HIGHLIGHT;
import static org.kie.workbench.common.stunner.core.client.shape.ShapeState.INVALID;
import static org.kie.workbench.common.stunner.core.client.shape.ShapeState.NONE;
import static org.kie.workbench.common.stunner.core.client.shape.ShapeState.SELECTED;
import static org.kie.workbench.common.stunner.core.client.shape.impl.ShapeStateAttributeHandler.ShapeStateAttribute.FILL_ALPHA;
import static org.kie.workbench.common.stunner.core.client.shape.impl.ShapeStateAttributeHandler.ShapeStateAttribute.FILL_COLOR;
import static org.kie.workbench.common.stunner.core.client.shape.impl.ShapeStateAttributeHandler.ShapeStateAttribute.STROKE_ALPHA;
import static org.kie.workbench.common.stunner.core.client.shape.impl.ShapeStateAttributeHandler.ShapeStateAttribute.STROKE_COLOR;

@RunWith(MockitoJUnitRunner.class)
public class ShapeStateAttributesFactoryTest {

private StunnerColorTheme theme = StunnerTheme.getTheme();
private Function<ShapeState, ShapeStateAttributeHandler.ShapeStateAttributes> stateAttributes = ShapeStateAttributesFactory::buildStateAttributes;

@Test
public void testBuildStrokeAttributes() {
ShapeStateAttributeHandler.ShapeStateAttributes attributes = stateAttributes.apply(NONE);
ShapeStateAttributeHandler.ShapeStateAttributes attributes = ShapeStateAttributesFactory.buildStateAttributes(ShapeState.NONE);
attributes.getValues().values().forEach(
state -> assertEquals(null, state)
);

assertStrokeAttributes(stateAttributes.apply(SELECTED), theme.getShapeStrokeColorSelected());
assertStrokeAttributes(stateAttributes.apply(HIGHLIGHT), theme.getShapeStrokeColorHighlight());
assertStrokeAttributes(stateAttributes.apply(INVALID), theme.getShapeStrokeColorInvalid());
assertStrokeAttributes(ShapeStateAttributesFactory.buildStateAttributes(ShapeState.SELECTED),
StunnerTheme.getTheme().getShapeStrokeColorSelected());
assertStrokeAttributes(ShapeStateAttributesFactory.buildStateAttributes(ShapeState.HIGHLIGHT),
StunnerTheme.getTheme().getShapeStrokeColorHighlight());
assertStrokeAttributes(ShapeStateAttributesFactory.buildStateAttributes(ShapeState.INVALID),
StunnerTheme.getTheme().getShapeStrokeColorInvalid());
}

@Test
public void testBuildFillAttributes() {
ShapeStateAttributeHandler.ShapeStateAttributes attributes = stateAttributes.apply(NONE);
ShapeStateAttributeHandler.ShapeStateAttributes attributes = ShapeStateAttributesFactory.buildStateAttributes(ShapeState.NONE);
attributes.getValues().values().forEach(
state -> assertEquals(null, state)
);

assertFillAttributes(stateAttributes.apply(SELECTED), theme.getShapeFillColorSelected());
assertFillAttributes(stateAttributes.apply(INVALID), theme.getShapeFillColorInvalid());
assertFillAttributes(ShapeStateAttributesFactory.buildStateAttributes(ShapeState.SELECTED),
StunnerTheme.getTheme().getShapeFillColorSelected());
assertFillAttributes(ShapeStateAttributesFactory.buildStateAttributes(ShapeState.INVALID),
StunnerTheme.getTheme().getShapeFillColorInvalid());
}

private void assertStrokeAttributes(ShapeStateAttributeHandler.ShapeStateAttributes attributes, String color) {
assertEquals(1d, attributes.getValues().get(STROKE_ALPHA));
assertEquals(color, attributes.getValues().get(STROKE_COLOR));
assertEquals(1d, attributes.getValues().get(ShapeStateAttributeHandler.ShapeStateAttribute.STROKE_ALPHA));
assertEquals(color, attributes.getValues().get(ShapeStateAttributeHandler.ShapeStateAttribute.STROKE_COLOR));
}

private void assertFillAttributes(ShapeStateAttributeHandler.ShapeStateAttributes attributes, String color) {
assertEquals(1d, attributes.getValues().get(FILL_ALPHA));
assertEquals(color, attributes.getValues().get(FILL_COLOR));
assertEquals(1d, attributes.getValues().get(ShapeStateAttributeHandler.ShapeStateAttribute.FILL_ALPHA));
assertEquals(color, attributes.getValues().get(ShapeStateAttributeHandler.ShapeStateAttribute.FILL_COLOR));
}
}

0 comments on commit fad41bf

Please sign in to comment.