站内搜索: 请输入搜索关键词
当前页面: 图书首页 > Java InstantCode: Developing Applications Using Java NIO

Unit Testing - Java InstantCode: Developing Applications Using Java NIO

Team LiB
Previous Section Next Section

Unit Testing

To test the Text Editor:

  1. Set the path of the bin directory of J2SDK by executing the following command at the command prompt:

    set path=%path%;D:\j2sdk1.4.0_02\bin;
    
  1. Set the classpath of the lib directory of J2SDK by executing the following command at the command prompt:

    set classpath = %classpath%;d:\j2sdk1.4.0_02\lib;
    
  1. Copy the Editor.java, ActionPerform.java, ColorClass.java, FontClass.java, PrintClass.java, and Help.java files to a folder on your computer. Compile the files using the following javac command:

    javac *.java
    
  1. To run the Text Editor, specify the following command at the command prompt:

    java Editor
    
  1. Select the File->New command from the menu bar. A new text file is opened in the Text Editor, as shown in Figure 6-7:

    Click To expand: This figure shows a new text file in the Text Editor.
    Figure 6-7: The Untitled Text Editor Window

  1. Write Hello, this is a sample file, in the currently untitled text file.

  2. Select the File->Save As command from the menu bar to save the file. A Save As dialog box appears, as shown in Figure 6-8:

    Click To expand: This figure shows the Save As dialog box. To save the untitled file, you need to specify a location and a file name.
    Figure 6-8: Save As Dialog Box

  1. In the Save As dialog box, specify the file name as Test and location as C:\CodeBook.

  2. Select the File->New command from the menu bar to clear the text area.

  3. Select the File->Open command from the menu bar to open the file, Test.txt. The Open dialog box appears, as shown in Figure 6-9:

    Click To expand: This figure shows the Open dialog box.
    Figure 6-9: Open Dialog Box

  1. Click the Open button of the Open dialog box that opens the Test.txt file from C:\CodeBook in the Text Editor, as shown in Figure 6-10:

    Click To expand: This figure shows the contents of the Test.txt file.
    Figure 6-10: Displaying the Test.txt File

  1. Select the Format->Font command from the menu bar to open the Font dialog box, as shown in Figure 6-4. Specify the font as Verdana, size as 20, and style as Italic. Click the OK button to apply the font changes to the file, as shown in Figure 6-11:

    Click To expand: This figure shows the Test.txt file that has been modified to Verdana, 20 points, italic.
    Figure 6-11: Displaying the Test.txt File with Selected Font

  1. Select the Format->Color command from the menu bar to open the Color dialog box, as shown in Figure 6-10. Specify the RGB values in this dialog box and click OK. The color of the file is modified, as shown in Figure 6-12:

    Click To expand: This figure shows the contents of the Test.txt file modified to blue.
    Figure 6-12: Displaying the Test.txt File with Selected Color

  1. Select the Lock->Exclusive Lock command from the menu bar. This locks the Test.txt file.

  2. Select the Start->Programs->Accessories->Notepad command to open a Windows notepad utility.

  3. Select the File->Open command from the menu bar of the Notepad utility. Open the Text.txt file from the C:\CodeBook location.

  4. Change the contents of the file and select the File->Save command from the menu bar. An error message appears because the file is locked, as shown in Figure 6-13:

    Click To expand: This figure shows an error message box that is appears when an enduser tries to modify a locked file.
    Figure 6-13: Displaying Error Message


Team LiB
Previous Section Next Section