Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Truth |
|
| 2.0;2 | ||||
Truth$1 |
|
| 2.0;2 | ||||
Truth$2 |
|
| 2.0;2 |
1 | /* | |
2 | * Copyright (c) 2011 David Saff | |
3 | * Copyright (c) 2011 Christian Gruber | |
4 | * | |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | * you may not use this file except in compliance with the License. | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | package org.truth0; | |
18 | ||
19 | import org.junit.internal.AssumptionViolatedException; | |
20 | ||
21 | import com.google.common.annotations.GwtCompatible; | |
22 | import com.google.common.annotations.GwtIncompatible; | |
23 | ||
24 | /** | |
25 | * Truth - a proposition framework for tests, supporting JUnit style | |
26 | * assertion and assumption semantics in a fluent style. | |
27 | * | |
28 | * Truth is the simplest entry point class. A developer can statically | |
29 | * import the ASSERT and ASSUME constants to get easy access to the | |
30 | * library's capabilities. Then, instead of writing: | |
31 | * <pre>{@code | |
32 | * Assert.assertEquals(a,b); | |
33 | * Assert.assertTrue(c); | |
34 | * Assert.assertTrue(d.contains(a) && d.contains(e)); | |
35 | * Assert.assertTrue(d.contains(a) || d.contains(q) || d.contains(z)); | |
36 | * }</pre> | |
37 | * one would write: | |
38 | * <pre>{@code | |
39 | * ASSERT.that(a).equals(b); | |
40 | * ASSERT.that(c).isTrue(); | |
41 | * ASSERT.that(d).contains(a).and().contains(b); | |
42 | * // or | |
43 | * ASSERT.that(d).containsAllOf(a, b); | |
44 | * ASSERT.that(d).containsAnyOf(a, q, z); | |
45 | * }</pre> | |
46 | * | |
47 | * Tests should be easier to read, and flow more clearly. | |
48 | * | |
49 | * @author David Saff | |
50 | * @author Christian Gruber (cgruber@israfil.net) | |
51 | */ | |
52 | @GwtCompatible(emulated = true) | |
53 | 0 | public class Truth { |
54 | 1 | public static final FailureStrategy THROW_ASSERTION_ERROR = |
55 | 1 | new FailureStrategy() { |
56 | @Override public void fail(String message) { | |
57 | 73 | throw new AssertionError(message); |
58 | } | |
59 | }; | |
60 | ||
61 | @GwtIncompatible("JUnit4") | |
62 | 1 | public static final FailureStrategy THROW_ASSUMPTION_ERROR = |
63 | 1 | new FailureStrategy() { |
64 | @Override public void fail(String message) { | |
65 | 2 | throw new AssumptionViolatedException(message); |
66 | } | |
67 | }; | |
68 | ||
69 | 1 | public static final TestVerb ASSERT = new TestVerb(THROW_ASSERTION_ERROR); |
70 | ||
71 | @GwtIncompatible("JUnit4") | |
72 | 1 | public static final TestVerb ASSUME = new TestVerb(THROW_ASSUMPTION_ERROR); |
73 | } |