- Add JUnit 5 Jupiter dependencies to pom.xml - Add maven-surefire-plugin for test execution - Add AbstractShapeTest for base class methods - Add SCircleTest, SRectangleTest, STriangleTest, STextTest Tests cover: creation, bounds, clone, resize (AbstractShape)
48 lines
1.4 KiB
Java
48 lines
1.4 KiB
Java
package ovh.gasser.newshapes.shapes;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
import java.awt.Font;
|
|
import java.awt.Rectangle;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class STextTest {
|
|
@Test
|
|
void testCreate() {
|
|
SText text = SText.create(10, 20, "Hello");
|
|
assertNotNull(text);
|
|
assertEquals("Hello", text.getText());
|
|
}
|
|
|
|
@Test
|
|
void testCreateWithDefaultValues() {
|
|
SText text = SText.create(0, 0, "Test");
|
|
assertEquals("Test", text.getText());
|
|
assertEquals(SText.DEFAULT_FONT_SIZE, text.getFontSize());
|
|
assertEquals(SText.DEFAULT_FONT_NAME, text.getFontName());
|
|
assertEquals(SText.DEFAULT_FONT_STYLE, text.getFontStyle());
|
|
}
|
|
|
|
@Test
|
|
void testCloneCreatesIndependentCopy() {
|
|
SText original = SText.create(5, 5, "Copy");
|
|
Object cloneObj = original.clone();
|
|
assertNotSame(original, cloneObj);
|
|
assertTrue(cloneObj instanceof SText);
|
|
SText clone = (SText) cloneObj;
|
|
assertEquals(original.getText(), clone.getText());
|
|
}
|
|
|
|
@Test
|
|
void testPlaceholderTextForEmpty() {
|
|
SText text = SText.create(0, 0, "");
|
|
assertEquals(SText.PLACEHOLDER_TEXT, text.getText());
|
|
}
|
|
|
|
@Test
|
|
void testPlaceholderTextForNull() {
|
|
SText text = SText.create(0, 0, null);
|
|
assertEquals(SText.PLACEHOLDER_TEXT, text.getText());
|
|
}
|
|
}
|