In Class Test

 

  1. Given the 4 @Test methods shown, how many times does the @Before method execute?
    Just one, it initializes global variables. In this case, we are creating objects from the class we want to test.
  2. The contract for equals() states that no exceptions may be thrown. Instead, equals() is supposed to return false if passed a null argument.
    Write a JUnit test that verifies this property for the EH class.

    @Test public void noNPE() {
           assertEquals(false, eh1.equals(null));
    }
  3. Using the given EH objects, write a test that verifies that equals() returns false if the objects are, in fact, not equal.
    @Test public void equalsFalse() {
           assertEquals(false, eh1.equals(eh2));
    }
  4. Using the given EH objects, write a test that verifies that equals() returns true if the objects are, in fact, equal.
    @Test public void equalsTrue() {
           assertEquals(true, eh1.equals(eh3));
    }
  5. Using the given EH objects, write a test to verify that hashCode() is consistent with equals. This test should fail if hashCode() is commented out (as shown), but pass if hashCode() is implemented.
    @Test public void hashConsistent() {
           assertEquals(true, eh1.hashCode() == eh3.hashCode());
    }
Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s