diff --git a/src/test/java/ovh/gasser/newshapes/exporters/HTMLExporterTest.java b/src/test/java/ovh/gasser/newshapes/exporters/HTMLExporterTest.java new file mode 100644 index 0000000..b8b93d6 --- /dev/null +++ b/src/test/java/ovh/gasser/newshapes/exporters/HTMLExporterTest.java @@ -0,0 +1,128 @@ +package ovh.gasser.newshapes.exporters; + +import ovh.gasser.newshapes.HTMLExporter; +import ovh.gasser.newshapes.shapes.SCircle; +import ovh.gasser.newshapes.shapes.SCollection; +import ovh.gasser.newshapes.shapes.SRectangle; +import ovh.gasser.newshapes.ui.visitors.HTMLDraftman; + +import java.awt.*; +import java.io.PrintWriter; +import java.io.StringWriter; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; + +class HTMLExporterTest { + + @Test + void testExportCreatesValidHtmlStructure() throws Exception { + SCollection model = SCollection.of( + SRectangle.create(10, 20, 100, 50, Color.RED) + ); + + StringWriter htmlBuffer = new StringWriter(); + StringWriter cssBuffer = new StringWriter(); + PrintWriter htmlWriter = new PrintWriter(htmlBuffer); + PrintWriter cssWriter = new PrintWriter(cssBuffer); + HTMLDraftman draftman = new HTMLDraftman(htmlWriter, cssWriter); + draftman.generateHTML(model); + + String htmlOutput = htmlBuffer.toString(); + String cssOutput = cssBuffer.toString(); + + assertTrue(htmlOutput.contains(""), "HTML should contain DOCTYPE"); + assertTrue(htmlOutput.contains(""), "HTML should contain head tag"); + assertTrue(htmlOutput.contains("
"), "HTML should contain body tag"); + assertTrue(htmlOutput.contains(""), "HTML should close body tag"); + assertTrue(htmlOutput.contains("style.css"), "HTML should reference stylesheet"); + } + + @Test + void testExportRectangleGeneratesCorrectDiv() throws Exception { + SRectangle rect = SRectangle.create(10, 20, 100, 50, Color.BLUE); + SCollection model = SCollection.of(rect); + + StringWriter htmlBuffer = new StringWriter(); + StringWriter cssBuffer = new StringWriter(); + PrintWriter htmlWriter = new PrintWriter(htmlBuffer); + PrintWriter cssWriter = new PrintWriter(cssBuffer); + HTMLDraftman draftman = new HTMLDraftman(htmlWriter, cssWriter); + draftman.generateHTML(model); + + String htmlOutput = htmlBuffer.toString(); + String cssOutput = cssBuffer.toString(); + + assertTrue(htmlOutput.contains("rec"), "HTML should contain rectangle div"); + assertTrue(cssOutput.contains("top:20px"), "CSS should contain correct top position"); + assertTrue(cssOutput.contains("left:10px"), "CSS should contain correct left position"); + assertTrue(cssOutput.contains("width:100px"), "CSS should contain correct width"); + assertTrue(cssOutput.contains("height:50px"), "CSS should contain correct height"); + } + + @Test + void testExportCircleGeneratesCorrectDiv() throws Exception { + SCircle circle = SCircle.create(50, 50, 30, Color.GREEN); + SCollection model = SCollection.of(circle); + + StringWriter htmlBuffer = new StringWriter(); + StringWriter cssBuffer = new StringWriter(); + PrintWriter htmlWriter = new PrintWriter(htmlBuffer); + PrintWriter cssWriter = new PrintWriter(cssBuffer); + HTMLDraftman draftman = new HTMLDraftman(htmlWriter, cssWriter); + draftman.generateHTML(model); + + String htmlOutput = htmlBuffer.toString(); + String cssOutput = cssBuffer.toString(); + + assertTrue(htmlOutput.contains("circle"), "HTML should contain circle class"); + assertTrue(cssOutput.contains("border-radius"), "CSS should contain border-radius for circle"); + } + + @Test + void testExportEmptyCollection() throws Exception { + SCollection model = SCollection.of(); + + StringWriter htmlBuffer = new StringWriter(); + StringWriter cssBuffer = new StringWriter(); + PrintWriter htmlWriter = new PrintWriter(htmlBuffer); + PrintWriter cssWriter = new PrintWriter(cssBuffer); + HTMLDraftman draftman = new HTMLDraftman(htmlWriter, cssWriter); + draftman.generateHTML(model); + + String htmlOutput = htmlBuffer.toString(); + + assertTrue(htmlOutput.contains(""), "HTML should contain DOCTYPE"); + assertTrue(htmlOutput.contains(""), "HTML should contain body tag"); + assertTrue(htmlOutput.contains(""), "HTML should close body tag"); + } + + @Test + void testExportNestedCollection() throws Exception { + SCollection nested = SCollection.of( + SRectangle.create(0, 0, 10, 10, Color.RED), + SRectangle.create(20, 0, 10, 10, Color.BLUE) + ); + SCollection model = SCollection.of(nested); + + StringWriter htmlBuffer = new StringWriter(); + StringWriter cssBuffer = new StringWriter(); + PrintWriter htmlWriter = new PrintWriter(htmlBuffer); + PrintWriter cssWriter = new PrintWriter(cssBuffer); + HTMLDraftman draftman = new HTMLDraftman(htmlWriter, cssWriter); + draftman.generateHTML(model); + + String htmlOutput = htmlBuffer.toString(); + + assertTrue(htmlOutput.contains("rec"), "HTML should contain rectangles"); + } + + @Test + void testHTMLExporterConstructorWithModel() { + SCollection model = SCollection.of(SRectangle.create(1, 2, 3, 4)); + HTMLExporter exporter = new HTMLExporter(model); + + assertNotNull(exporter); + } +} diff --git a/src/test/java/ovh/gasser/newshapes/exporters/SVGExporterTest.java b/src/test/java/ovh/gasser/newshapes/exporters/SVGExporterTest.java new file mode 100644 index 0000000..27beac3 --- /dev/null +++ b/src/test/java/ovh/gasser/newshapes/exporters/SVGExporterTest.java @@ -0,0 +1,135 @@ +package ovh.gasser.newshapes.exporters; + +import ovh.gasser.newshapes.SVGExporter; +import ovh.gasser.newshapes.attributes.ColorAttributes; +import ovh.gasser.newshapes.shapes.SCircle; +import ovh.gasser.newshapes.shapes.SCollection; +import ovh.gasser.newshapes.shapes.SRectangle; +import ovh.gasser.newshapes.ui.visitors.SVGDraftman; + +import java.awt.*; +import java.io.PrintWriter; +import java.io.StringWriter; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; + +class SVGExporterTest { + + @Test + void testExportCreatesValidSvgStructure() throws Exception { + SCollection model = SCollection.of( + SRectangle.create(10, 20, 100, 50) + ); + + StringWriter buffer = new StringWriter(); + PrintWriter writer = new PrintWriter(buffer); + SVGDraftman draftman = new SVGDraftman(writer); + draftman.generateSVG(model); + + String output = buffer.toString(); + + assertTrue(output.contains(""), "SVG should contain XML declaration"); + assertTrue(output.contains("