testmovie.java

来自「Thinking in Java 是学习JAVA的经典教材」· Java 代码 · 共 57 行

JAVA
57
字号
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
package javatheater.test;

import javatheater.ejb.*;
import javax.naming.*;
import junit.framework.*;

public class TestMovie extends TestCase {
  MovieHome movieHome;

  public TestMovie(String name) {
    super(name);
  }

  public void setUp() {
    try {
      Object objRef = new InitialContext().lookup("javatheater/Movie");
      movieHome
        = (MovieHome) javax.rmi.PortableRemoteObject.narrow(
         objRef, MovieHome.class);
    }
    catch (Exception e) {
      fail("Error getting home interfaces: " + e.toString());
    }
  }

  public void testCreateRemove() {
    try {
      int pkValue = (int) System.currentTimeMillis() % Integer.MAX_VALUE;

      Movie movie = movieHome.create(
        new Integer(pkValue),
        "The Return of the JNDI"
      );

      movie.remove();
    }
    catch (Exception e) {
      fail(e.toString());
    }
  }

  public void testFinder() {
    try {
      int pkValue = (int) System.currentTimeMillis() % Integer.MAX_VALUE;

      Movie movie = movieHome.create(new Integer(pkValue), "The Object Of My Affection");
      movie = movieHome.findByPrimaryKey(new Integer(pkValue));
      assertEquals(movie.getTitle(), "The Object Of My Affection");
      movie.remove();
    }
    catch (Exception e) {
      fail(e.toString());
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?