I thought this would be a trivial matter, but I can't seem to find a method similar to class_exists
in Java. I'm writing a test to verify that a class name is defined. How can I replicate this in Java with jUnit?
<?php
$this->assertTrue(class_exists('Car'), 'Should have a class called "Car"');
TestCar.java
import org.junit.Assert;
import org.junit.Test;
public class TestCar {
@Test
public void testCarExists() {
try {
Class.forName("Car");
} catch(ClassNotFoundException e) {
Assert.fail("Should create a class called 'Car'.");
}
}
}
Car.java
public class Car {
// just enough :-)
}