import junit.framework.Assert;
import junit.framework.TestCase;
import com.test.Largest;
public class TestLargest extends TestCase {
Largest l;
@Override
protected void setUp() throws Exception {
l = new Largest();
}
public void testGetL() {
int[] array = { 23, 45, 67, 345, 78, 222, 999 };
int result = 0;
;
try {
result = l.getLargest(array);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals(999, result);
}
public void testGetL2() {
int[] array = {};
Throwable tx = null;
try {
l.getLargest(array);
Assert.fail();
} catch (Exception ex) {
tx = ex;
}
Assert.assertNotNull(tx);
Assert.assertEquals(Exception.class, tx.getClass());
Assert.assertEquals("数组不能为空!", tx.getMessage());
}
public void testGetL3() {
Throwable tx = null;
try {
int[] array = null;
l.getLargest(array);
Assert.fail();
} catch (Exception ex) {
tx = ex;
}
Assert.assertNotNull(tx);
Assert.assertEquals(Exception.class, tx.getClass());
Assert.assertEquals("数组不能为空!", tx.getMessage());
}
}