|
1 | 1 | /* |
2 | | - * Copyright 2002-2012 the original author or authors. |
| 2 | + * Copyright 2002-2013 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
24 | 24 | import java.util.Map; |
25 | 25 | import java.util.Set; |
26 | 26 |
|
| 27 | +import org.junit.Rule; |
27 | 28 | import org.junit.Test; |
| 29 | +import org.junit.rules.ExpectedException; |
28 | 30 |
|
29 | 31 | /** |
30 | 32 | * Unit tests for the {@link Assert} class. |
|
36 | 38 | */ |
37 | 39 | public class AssertTests { |
38 | 40 |
|
| 41 | + @Rule |
| 42 | + public ExpectedException thrown = ExpectedException.none(); |
| 43 | + |
39 | 44 | @Test(expected = IllegalArgumentException.class) |
40 | 45 | public void instanceOf() { |
41 | 46 | final Set<?> set = new HashSet<Object>(); |
42 | 47 | Assert.isInstanceOf(HashSet.class, set); |
43 | 48 | Assert.isInstanceOf(HashMap.class, set); |
44 | 49 | } |
45 | 50 |
|
| 51 | + @Test |
| 52 | + public void instanceOfNoMessage() throws Exception { |
| 53 | + thrown.expect(IllegalArgumentException.class); |
| 54 | + thrown.expectMessage("Object of class [java.lang.Object] must be an instance " + |
| 55 | + "of interface java.util.Set"); |
| 56 | + Assert.isInstanceOf(Set.class, new Object(), null); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void instanceOfMessage() throws Exception { |
| 61 | + thrown.expect(IllegalArgumentException.class); |
| 62 | + thrown.expectMessage("Custom message. Object of class [java.lang.Object] must " + |
| 63 | + "be an instance of interface java.util.Set"); |
| 64 | + Assert.isInstanceOf(Set.class, new Object(), "Custom message."); |
| 65 | + } |
| 66 | + |
46 | 67 | @Test |
47 | 68 | public void isNullDoesNotThrowExceptionIfArgumentIsNullWithMessage() { |
48 | 69 | Assert.isNull(null, "Bla"); |
|
0 commit comments