📄 testmediafile.java
字号:
import java.io.*;
import java.lang.reflect.*;
/**
* Test driver for class <code>MediaFile</code>.
*
* @author iCarnegie
* @version 1.0.0
* @see AudioFile
*/
public class TestMediaFile {
/* Standard output stream */
private static PrintWriter stdOut =
new PrintWriter(System.out, true);
/* Standard error stream */
private static PrintWriter stdErr =
new PrintWriter(System.err, true);
/**
* Displays a message in the standard error stream if the value specified
* by parameter <code>condition<code> is <code>false</code>.
*
* @param message the error message.
* @param condition the test condition.
*/
public static void assertTrue(String message, boolean condition) {
if (! condition) {
stdErr.print("** Test failure ");
stdErr.println(message);
System.exit(0);
}
}
/**
* Displays a message in the standard error stream.
*
* @param message the error message.
*/
public static void fail(String message) {
stdErr.print("** Test failure ");
stdErr.println(message);
System.exit(0);
}
/**
* Test driver for interface <code>MediaFile</code>.
*
* @param args not used.
*/
public static void main(String[] args) {
stdOut.println("");
stdOut.println("Testing interface MediaFile...");
MediaFile file;
Class interfaceDescriptor = null;
try {
interfaceDescriptor = Class.forName("MediaFile");
} catch (ClassNotFoundException cnfe) {
fail("1: Interface MediaFile not found " +
"(check the name of the interface)");
}
assertTrue("2: MediaFile is not an Interface",
interfaceDescriptor.isInterface());
Method[] methods = interfaceDescriptor.getMethods();
if (methods.length == 0) {
fail("3: MediaFile contains no methods");
}
assertTrue("4: MediaFile should contain only one method",
methods.length == 1);
try {
Method method =
interfaceDescriptor.getMethod("getName", new Class[0]);
} catch (NoSuchMethodException nsme) {
fail("5: Method getName() not found " +
"(check the method signature)");
}
stdOut.println("done");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -