Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions jhotdraw-samples/jhotdraw-samples-misc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.jgiven</groupId>
<artifactId>jgiven-junit</artifactId>
<version>0.18.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.jhotdraw.samples.svg.gui;

import org.jhotdraw.draw.figure.RectangleFigure;
import org.junit.Test;

import java.awt.Color;

import static org.junit.Assert.*;
import static org.jhotdraw.samples.svg.SVGAttributeKeys.*;

public class StrokeAttributeTest {

@Test
public void testStrokeWidthBestCase() {
RectangleFigure figure = new RectangleFigure();
double width = 5.0;

figure.set(STROKE_WIDTH, width);

assertEquals(width, figure.get(STROKE_WIDTH), 0.0001);
}

@Test
public void testStrokeColorBestCase() {
RectangleFigure figure = new RectangleFigure();
Color color = Color.BLUE;

figure.set(STROKE_COLOR, color);

assertEquals(color, figure.get(STROKE_COLOR));
}

@Test
public void testStrokeWidthZeroBoundary() {
RectangleFigure figure = new RectangleFigure();
double width = 0.0;

figure.set(STROKE_WIDTH, width);

assertEquals(width, figure.get(STROKE_WIDTH), 0.0001);
}

@Test
public void testStrokeOpacityUpperBoundary() {
RectangleFigure figure = new RectangleFigure();
double opacity = 1.0;

figure.set(STROKE_OPACITY, opacity);

assertEquals(opacity, figure.get(STROKE_OPACITY), 0.0001);
}

@Test
public void testStrokeWidthInvariant() {
RectangleFigure figure = new RectangleFigure();
double width = 3.0;

figure.set(STROKE_WIDTH, width);

assert figure.get(STROKE_WIDTH) >= 0 : "Stroke width must never be negative";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.jhotdraw.samples.svg.gui;

import static org.junit.Assert.*;

public class StrokeToolBarTest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.jhotdraw.samples.svg.gui.bdd;

import com.tngtech.jgiven.Stage;
import org.jhotdraw.draw.figure.RectangleFigure;
import com.tngtech.jgiven.annotation.ProvidedScenarioState;


public class GivenStrokeFigure extends Stage<GivenStrokeFigure> {

@ProvidedScenarioState
RectangleFigure figure;

public GivenStrokeFigure a_selected_rectangle_figure() {
figure = new RectangleFigure();
return self();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.jhotdraw.samples.svg.gui.bdd;

import com.tngtech.jgiven.junit.ScenarioTest;
import org.junit.Test;


public class StrokePaletteBDDTest
extends ScenarioTest<GivenStrokeFigure, WhenStrokeChanged, ThenStrokeResult> {

@Test
public void changing_stroke_width_updates_selected_figure() {
given().a_selected_rectangle_figure();
when().the_stroke_width_is_changed_to(4.0);
then().the_figure_should_have_stroke_width(4.0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jhotdraw.samples.svg.gui.bdd;

import com.tngtech.jgiven.Stage;
import com.tngtech.jgiven.annotation.ExpectedScenarioState;
import org.jhotdraw.draw.figure.RectangleFigure;

import static org.assertj.core.api.Assertions.*;
import static org.jhotdraw.samples.svg.SVGAttributeKeys.*;

public class ThenStrokeResult extends Stage<ThenStrokeResult> {

@ExpectedScenarioState
RectangleFigure figure;

public ThenStrokeResult the_figure_should_have_stroke_width(double width) {
assertThat(figure.get(STROKE_WIDTH))
.as("Stroke width should be updated")
.isEqualTo(width);
return self();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.jhotdraw.samples.svg.gui.bdd;

import com.tngtech.jgiven.Stage;
import static org.jhotdraw.samples.svg.SVGAttributeKeys.*;
import com.tngtech.jgiven.annotation.ExpectedScenarioState;
import org.jhotdraw.draw.figure.RectangleFigure;


public class WhenStrokeChanged extends Stage<WhenStrokeChanged> {

@ExpectedScenarioState
RectangleFigure figure;

public WhenStrokeChanged the_stroke_width_is_changed_to(double width) {
figure.set(STROKE_WIDTH, width);
return self();
}
}