public class EnumeratorTest { enum Class{ ClassA("Class 1", 40, "Bruce"), // Init the constructors by its parameters. ClassB("Class 2", 38, "Lee"), ClassC("Class 3", 42, "Daniel"), ClassD("Class 4", 20, "Anthony"); // Constructor must be set as Private. private Class(String className, int students, String classAdvisor){ _className = className; _students = students; _classAdvisor = classAdvisor; } String _className; int _students; String _classAdvisor; boolean _isSpecialClass = false; public String getClassName(){ return _className; } public int getStudentNum(){ return _students; } public String getClassAdvisor(){ return _classAdvisor; } // we can set the attributes public void setIsSpecialClass(boolean bol){ _isSpecialClass = bol; } public boolean getIsSpecialClass(){ return _isSpecialClass; } } @Test public void testEnum(){ Class classA = Class.ClassA; // get the enum instance by access the attribute Assert.assertEquals( "Class name equals", "Class 1", classA.getClassName() ); Assert.assertEquals( "Student num equals", 40, classA.getStudentNum() ); Assert.assertEquals( "Class advisor name", "Bruce", classA.getClassAdvisor() ); Assert.assertEquals( "Special class or not", false, classA.getIsSpecialClass() ); Class classD = Class.valueOf("ClassD"); // fetch the enum instance by valueOf(). classD.setIsSpecialClass( true ); // set it as the special class. Assert.assertEquals( "Class name equals", "Class 4", classD.getClassName() ); Assert.assertEquals( "Student num equals", 20, classD.getStudentNum() ); Assert.assertEquals( "Class advisor name", "Anthony", classD.getClassAdvisor() ); Assert.assertEquals( "Special class or not", true, classD.getIsSpecialClass() ); } }