Last active
January 4, 2016 00:49
-
-
Save mariuszs/8543918 to your computer and use it in GitHub Desktop.
BDD Style Catch Exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Test; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import static com.googlecode.catchexception.CatchException.caughtException; | |
import static com.googlecode.catchexception.apis.CatchExceptionAssertJ.then; | |
import static com.googlecode.catchexception.apis.CatchExceptionAssertJ.when; | |
public class FooBarTest { | |
FooBar sut = new FooBar(); // System Under Test | |
@Test | |
public void shouldThrowExceptionWhenListHasTooManyElements() { | |
when(sut).getMethod(listWithSize(101)); | |
then(caughtException()).isInstanceOf(IllegalArgumentException.class); | |
} | |
private ArrayList<String> listWithSize(int size) { | |
return new ArrayList<String>(Arrays.asList(new String[size])); | |
} | |
public class FooBar { | |
public int getMethod(List<String> code) throws IllegalArgumentException { | |
if (code.size() > 100) | |
throw new IllegalArgumentException(); | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment