Skip to content

Instantly share code, notes, and snippets.

@riethmayer
Created June 29, 2010 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riethmayer/457625 to your computer and use it in GitHub Desktop.
Save riethmayer/457625 to your computer and use it in GitHub Desktop.
// Doctype.java
/**
* Doctype definitions for HTML documents.
*/
public enum Doctype{
/** HTML 4.01 Strict */
HTML401_strict("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"),
/** XHTML 1.0 frameset */
XHTML1_0_frameset("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">"),
/** XHTML 1.0 strict */
XHTML1_0_strict("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"),
/** XHTML 1.0 transitional */
XHTML1_0_transitional("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"),
/** XHTML 1.1 */
XHTML1_1("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">"),
/** HTML 5 */
HTML5("<!DOCTYPE html>"),
/** Empty */
Empty("");
/** Doctype.java */
private String doctype;
/**
* Constructor for doctypes
* @param doctype
*/
Doctype(String doctype){
this.setDoctype(doctype);
}
/**
* @param doctype the doctype to set
*/
private void setDoctype(String doctype) {
this.doctype = doctype;
}
/**
* @return the doctype
*/
public String toString() {
return doctype;
}
}
// #DocTypeTest.java
import static org.junit.Assert.*;
import org.junit.Test;
/**
* Test Doctype definitions.
*/
public class DocTypeTest {
/**
* Test one specific doctype
*/
@Test
public void testHTML5() {
Doctype dt = Doctype.HTML5;
assertEquals("<!DOCTYPE html>", dt.toString());
}
/**
* All doctypes must return valid strings.
* @throws Exception
*/
@Test
public void testDoctypeMethodDefinedForAllDoctypes() throws Exception {
Doctype[] doctype = Doctype.values();
for (int i = 0; i < doctype.length; i++) {
assertTrue(doctype[i].toString().getClass() == String.class);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment