import java.lang.reflect.*; import org.junit.*; import static org.junit.Assert.*; /** * This class uses reflection to test various attributes of the Time class * that could be submitted by various CSE students. * @author Marty Stepp * @version CSE 331 Spring 2011, 5/27/2011 */ public class TimeStyleTest { /** * Fails if the student has any fields that are public. */ @Test(timeout=1000) public void noPublicFields() { for (Field f : Time.class.getFields()) { assertFalse(f.getName() + " should not have been public", Modifier.isPublic(f.getModifiers())); } } /** * Fails if the student has any methods that return an int. */ @Test(timeout=1000) public void noIntReturns() { for (Method m : Time.class.getMethods()) { assertNotSame(m.getName() + " should not return an int", int.class, m.getReturnType()); } } /** * Fails if the student has any methods that take 4 or more parameters. */ @Test(timeout=1000) public void noMethodsWithTooManyParameters() { for (Method m : Time.class.getMethods()) { assertTrue(m.getName() + " takes too many parameters", m.getParameterTypes().length <= 3); } } }