OLD | NEW |
(Empty) | |
| 1 library java.junit; |
| 2 |
| 3 import 'package:unittest/unittest.dart' hide fail; |
| 4 import 'package:unittest/unittest.dart' as _ut show fail; |
| 5 |
| 6 |
| 7 class JUnitTestCase { |
| 8 void setUp() {} |
| 9 void tearDown() {} |
| 10 static void fail(String msg) { |
| 11 _ut.fail(msg); |
| 12 } |
| 13 static void assertTrue(bool x) { |
| 14 expect(x, isTrue); |
| 15 } |
| 16 static void assertTrueMsg(String msg, bool x) { |
| 17 expect(x, isTrueMsg(msg)); |
| 18 } |
| 19 static void assertFalse(bool x) { |
| 20 expect(x, isFalse); |
| 21 } |
| 22 static void assertFalseMsg(String msg, bool x) { |
| 23 expect(x, isFalseMsg(msg)); |
| 24 } |
| 25 static void assertNull(x) { |
| 26 expect(x, isNull); |
| 27 } |
| 28 static void assertNullMsg(String msg, x) { |
| 29 expect(x, isNullMsg(msg)); |
| 30 } |
| 31 static void assertNotNull(x) { |
| 32 expect(x, isNotNull); |
| 33 } |
| 34 static void assertNotNullMsg(String msg, x) { |
| 35 expect(x, isNotNullMsg(msg)); |
| 36 } |
| 37 static void assertEquals(expected, actual) { |
| 38 expect(actual, equals(expected)); |
| 39 } |
| 40 static void assertEqualsMsg(String msg, expected, actual) { |
| 41 expect(actual, equalsMsg(msg, expected)); |
| 42 } |
| 43 static void assertSame(expected, actual) { |
| 44 expect(actual, same(expected)); |
| 45 } |
| 46 static void assertSameMsg(String msg, expected, actual) { |
| 47 expect(actual, sameMsg(msg, expected)); |
| 48 } |
| 49 static void assertNotSame(expected, actual) { |
| 50 expect(actual, notSame(expected)); |
| 51 } |
| 52 } |
| 53 |
| 54 runJUnitTest(testInstance, Function testFunction) { |
| 55 testInstance.setUp(); |
| 56 try { |
| 57 testFunction(); |
| 58 } finally { |
| 59 testInstance.tearDown(); |
| 60 } |
| 61 } |
| 62 |
| 63 /** |
| 64 * Returns a matches that matches if the value is not the same instance as "obje
ct" (`!==`). |
| 65 */ |
| 66 Matcher notSame(expected) => new _IsNotSameAs(expected); |
| 67 |
| 68 class _IsNotSameAs extends Matcher { |
| 69 final _expected; |
| 70 const _IsNotSameAs(this._expected); |
| 71 bool matches(item, Map matchState) => !identical(item, _expected); |
| 72 Description describe(Description description) => |
| 73 description.add('not same instance as ').addDescriptionOf(_expected); |
| 74 } |
| 75 |
| 76 Matcher equalsMsg(String msg, expected) => new _EqualsWithMessage(msg, expected)
; |
| 77 class _EqualsWithMessage extends Matcher { |
| 78 final String msg; |
| 79 final expectedValue; |
| 80 const _EqualsWithMessage(this.msg, this.expectedValue); |
| 81 bool matches(item, Map matchState) { |
| 82 return item == expectedValue; |
| 83 } |
| 84 Description describe(Description mismatchDescription) { |
| 85 return mismatchDescription.replace(msg); |
| 86 } |
| 87 } |
| 88 |
| 89 Matcher sameMsg(String msg, expected) => new _IsSameAsWithMessage(msg, expected)
; |
| 90 class _IsSameAsWithMessage extends Matcher { |
| 91 final String msg; |
| 92 final _expected; |
| 93 const _IsSameAsWithMessage(this.msg, this._expected); |
| 94 bool matches(item, Map matchState) => identical(item, _expected); |
| 95 Description describe(Description description) => description.add(msg).addDescr
iptionOf(_expected); |
| 96 } |
| 97 |
| 98 Matcher isTrueMsg(String msg) => new _IsTrueWithMessage(msg); |
| 99 class _IsTrueWithMessage extends Matcher { |
| 100 final String msg; |
| 101 const _IsTrueWithMessage(this.msg); |
| 102 bool matches(item, Map matchState) { |
| 103 return item == true; |
| 104 } |
| 105 Description describe(Description mismatchDescription) { |
| 106 return mismatchDescription.replace(msg); |
| 107 } |
| 108 } |
| 109 |
| 110 Matcher isFalseMsg(String msg) => new _IsFalseWithMessage(msg); |
| 111 class _IsFalseWithMessage extends Matcher { |
| 112 final String msg; |
| 113 const _IsFalseWithMessage(this.msg); |
| 114 bool matches(item, Map matchState) { |
| 115 return item == false; |
| 116 } |
| 117 Description describe(Description mismatchDescription) { |
| 118 return mismatchDescription.replace(msg); |
| 119 } |
| 120 } |
| 121 |
| 122 Matcher isNullMsg(String msg) => new _IsNullWithMessage(msg); |
| 123 class _IsNullWithMessage extends Matcher { |
| 124 final String msg; |
| 125 const _IsNullWithMessage(this.msg); |
| 126 bool matches(item, Map matchState) { |
| 127 return item == null; |
| 128 } |
| 129 Description describe(Description mismatchDescription) { |
| 130 return mismatchDescription.replace(msg); |
| 131 } |
| 132 } |
| 133 |
| 134 Matcher isNotNullMsg(String msg) => new _IsNotNullWithMessage(msg); |
| 135 class _IsNotNullWithMessage extends Matcher { |
| 136 final String msg; |
| 137 const _IsNotNullWithMessage(this.msg); |
| 138 bool matches(item, Map matchState) { |
| 139 return item != null; |
| 140 } |
| 141 Description describe(Description mismatchDescription) { |
| 142 return mismatchDescription.replace(msg); |
| 143 } |
| 144 } |
OLD | NEW |