📄 testtableprimitive.java
字号:
package com.wiley.compBooks.EJwithUML.Base.HtmlPrimitives.Layout;import junit.framework.TestCase;import com.wiley.compBooks.EJwithUML.Base.TestUtilities.*;import com.wiley.compBooks.EJwithUML.Base.HtmlPrimitives.ContentElements.*;import com.wiley.compBooks.EJwithUML.Base.HtmlPrimitives.Core.*;import java.io.*;public class TestTablePrimitive extends TestCase{ private TestFileSet testFileSet; private ImagePrimitive image; private TextPrimitive text; public TestTablePrimitive(String name) throws IOException { super(name); testFileSet = new TestFileSet("C:/EJwithUML2e/UnitTestResults/HtmlPrimitives/Layout/TablePrimitive/"); image = new ImagePrimitive("./pic.jpg"); image.setSize(50,50); text = new TextPrimitive("Hi there"); text.addLineBreak(); text.addText("Again"); } public void testEmptyTable() throws IOException { StringBuffer buffer = new StringBuffer(); TablePrimitive table = new TablePrimitive(); PagePrimitive page = new PagePrimitive("test", "../../Default.css"); page.addToBody(table); page.buildContent(buffer); boolean match = testFileSet.fileMatchesGold("EmptyTable.html", buffer.toString()); assertEquals("EmptyTable", match, true); } public void testTopRightAlignmentInPage() throws IOException { StringBuffer buffer = new StringBuffer(); TablePrimitive table = new TablePrimitive(); table.setAlignment(HAlignment.RIGHT, VAlignment.TOP); table.setPrimitiveAt(0,0,image); table.setPrimitiveAt(1,1,image); PagePrimitive page = new PagePrimitive("test", "../../Default.css"); page.addToBody(table); page.buildContent(buffer); boolean match = testFileSet.fileMatchesGold("TopRightAlignmentInPage.html", buffer.toString()); assertEquals("TopRightAlignmentInPage", match, true); } public void testBotomLeftAlignmentInPage() throws IOException { StringBuffer buffer = new StringBuffer(); TablePrimitive table = new TablePrimitive(); table.setAlignment(HAlignment.LEFT, VAlignment.BOTTOM); table.setPrimitiveAt(0,0,image); table.setPrimitiveAt(1,1,image); PagePrimitive page = new PagePrimitive("test", "../../Default.css"); page.addToBody(table); page.buildContent(buffer); boolean match = testFileSet.fileMatchesGold("BotomLeftAlignmentInPage.html", buffer.toString()); assertEquals("BotomLeftAlignmentInPage", match, true); } public void testAlignmentOfRowInTable() throws IOException { StringBuffer buffer = new StringBuffer(); TablePrimitive table = new TablePrimitive(); table.setStyle(Style.DEBUG_TABLE); table.setPrimitiveAt(0,0,image); table.setPrimitiveAt(0,1,text); table.setPrimitiveAt(0,2,image); table.setPrimitiveAt(1,0,image); table.setPrimitiveAt(2,0,image); table.setAlignmentForRow(0, HAlignment.LEFT, VAlignment.TOP); table.setAlignmentForRow(1, HAlignment.CENTER, null); table.setAlignmentForRow(2, HAlignment.RIGHT, VAlignment.BOTTOM); PagePrimitive page = new PagePrimitive("test", "../../Default.css"); page.addToBody(table); page.buildContent(buffer); boolean match = testFileSet.fileMatchesGold("AlignmentOfRowInTable.html", buffer.toString()); assertEquals("AlignmentOfRowInTable", match, true); } public void testAlignmentOfCellsInTable() throws IOException { StringBuffer buffer = new StringBuffer(); TablePrimitive table = new TablePrimitive(); table.setStyle(Style.DEBUG_TABLE); table.setAlignmentForCells(HAlignment.CENTER, null); table.setPrimitiveAt(0,0,image); table.setPrimitiveAt(0,1,text); table.setPrimitiveAt(0,2,image); table.setPrimitiveAt(1,0,image); table.setAlignmentForCells(HAlignment.LEFT, VAlignment.TOP); table.setPrimitiveAt(1,1,text); table.setPrimitiveAt(1,2,image); table.setPrimitiveAt(2,0,image); table.setAlignmentForCells(HAlignment.RIGHT, VAlignment.BOTTOM); table.setPrimitiveAt(2,1,text); table.setPrimitiveAt(2,2,image); PagePrimitive page = new PagePrimitive("test", "../../Default.css"); page.addToBody(table); page.buildContent(buffer); boolean match = testFileSet.fileMatchesGold("AlignmentOfCellsInTable.html", buffer.toString()); assertEquals("AlignmentOfCellsInTable", match, true); } public void testStyles() throws IOException { StringBuffer buffer = new StringBuffer(); TablePrimitive table = new TablePrimitive(); table.setPrimitiveAt(0,0,text); table.setPrimitiveAt(1,1,text); table.setStyleForCells(Style.FINEPRINT_TEXT); table.setPrimitiveAt(2,2,text); table.setPrimitiveAt(3,3,text); PagePrimitive page = new PagePrimitive("test", "../../Default.css"); page.addToBody(table); page.buildContent(buffer); boolean match = testFileSet.fileMatchesGold("Styles.html", buffer.toString()); assertEquals("Styles", match, true); } public void testColumnSpan() throws IOException { StringBuffer buffer = new StringBuffer(); TablePrimitive table = new TablePrimitive(); table.setColumnSpanForCells(3); table.setAlignmentForCells(HAlignment.CENTER, null); table.setPrimitiveAt(0,0,new TextPrimitive("Title of Table")); table.setColumnSpanForCells(1); table.setAlignmentForCells(HAlignment.LEFT, null); table.setPrimitiveAt(1,0, new TextPrimitive("value1")); table.setPrimitiveAt(1,1, new TextPrimitive("value2")); table.setPrimitiveAt(1,2, new TextPrimitive("value3")); PagePrimitive page = new PagePrimitive("test", "../../Default.css"); page.addToBody(table); page.buildContent(buffer); boolean match = testFileSet.fileMatchesGold("ColumnSpan.html", buffer.toString()); assertEquals("ColumnSpan", match, true); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -