fork download
  1. package junitdemo;
  2.  
  3. import static org.hamcrest.CoreMatchers.is;
  4. import static org.junit.Assert.assertThat;
  5. import static org.junit.Assert.fail;
  6.  
  7. import java.util.ArrayList;
  8.  
  9. import org.junit.Test;
  10.  
  11. public class ExceptionTests {
  12.  
  13. @Test(expected = IndexOutOfBoundsException.class)
  14. public void empty() {
  15. new ArrayList<Object>().get(0);
  16. }
  17.  
  18. @Test
  19. public void testExceptionMessage() {
  20. try {
  21. new ArrayList<Object>().get(0);
  22. fail("Expected an IndexOutOfBoundsException to be thrown");
  23. } catch (IndexOutOfBoundsException anIndexOutOfBoundsException) {
  24. assertThat(anIndexOutOfBoundsException.getMessage(),
  25. is("Index: 0, Size: 0"));
  26. }
  27. }
  28.  
  29.  
  30. }
  31.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:11: error: class ExceptionTests is public, should be declared in a file named ExceptionTests.java
public class ExceptionTests {
       ^
Main.java:3: error: package org.hamcrest does not exist
import static org.hamcrest.CoreMatchers.is;
                          ^
Main.java:3: error: static import only from classes and interfaces
import static org.hamcrest.CoreMatchers.is;
^
Main.java:4: error: package org.junit does not exist
import static org.junit.Assert.assertThat;
                       ^
Main.java:4: error: static import only from classes and interfaces
import static org.junit.Assert.assertThat;
^
Main.java:5: error: package org.junit does not exist
import static org.junit.Assert.fail;
                       ^
Main.java:5: error: static import only from classes and interfaces
import static org.junit.Assert.fail;
^
Main.java:9: error: package org.junit does not exist
import org.junit.Test;
                ^
Main.java:13: error: cannot find symbol
	@Test(expected = IndexOutOfBoundsException.class)
	 ^
  symbol:   class Test
  location: class ExceptionTests
Main.java:18: error: cannot find symbol
	@Test
	 ^
  symbol:   class Test
  location: class ExceptionTests
Main.java:22: error: cannot find symbol
			fail("Expected an IndexOutOfBoundsException to be thrown");
			^
  symbol:   method fail(String)
  location: class ExceptionTests
Main.java:25: error: cannot find symbol
					is("Index: 0, Size: 0"));
					^
  symbol:   method is(String)
  location: class ExceptionTests
12 errors
stdout
Standard output is empty