Unit Testing


To test the Encoder/Decoder application:

  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 EncoderDecoder.java and EncodingSchemes.java files to a folder on your computer. On the command prompt, use the cd command to move to the folder where you have copied the Java files. Compile the files using the following javac command:

     javac *.java 
  1. To run the Encoder/Decoder application, specify the following command at the command prompt:

     java EncoderDecoder 

    The above code opens the main window of the Encoder/Decoder application, as shown in Figure 8-2.

  1. Click the Browse button and select the test.txt file from the C drive of the computer.

    Figure 8-4 shows the contents of the test.txt file:

    click to expand: this figure shows the contents of the test.txt file in the text to encode text area.
    Figure 8-4: Displaying test.txt File in the Encoder/Decoder Application

  1. Click the Select Encoding Scheme button to open the Encoding Schemes dialog box and select the UTF-16BE encoding scheme.

  2. Click the OK button of the Encoding Schemes dialog box.

  3. Click the Encode button to encode the test.txt file using the UTF-16BE encoding scheme, as shown in Figure 8-5:

    click to expand: this figure shows the encoded file in the encoded text text area of the encoder/decoder application.
    Figure 8-5: Displaying Encoded File in the Encoder/Decoder Application

  1. Click the Decode button to decode the encoded file, as shown in Figure 8-6:

    click to expand: this figure shows the decoded file in the decoded text text area of the encoder/decoder application.
    Figure 8-6: Displaying Decoded File in the Encoder/Decoder Application

  1. Click the Reset button to reset the Encoder/Decoder application.

  2. Specify the text you want to encode in the Text to Encode text area, as shown in Figure 8-7:

    click to expand: this figure shows a sample string, this is an encoder/decoder application., in the text to encode text area.
    Figure 8-7: Displaying Text to Encode in the Encoder/Decoder Application

  1. Repeat steps 6 through 9 to encode and decode the text specified in the Text to Encode text area. The results are displayed in Figure 8-8:

    click to expand: this figure shows the original, encoded, and decoded texts in the text to encode, encoded text, and decoded text text areas, respectively.
    Figure 8-8: Displaying Encoded and Decoded Text




Java InstantCode. Developing Applications Using Java NIO
Java InstantCode. Developing Applications Using Java NIO
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 55

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net