Best junit code snippet using org.hamcrest.StringDescription
Source:UsingShouldSpec.java
...45 public void _toPass() throws Exception {46 boolean _should_be = Should.<Boolean>should_be(47 Boolean.valueOf(true), true);48 Assert.assertTrue("\nExpected // equality\r\n true should be true but"49 + "\n // equality\r\n true should be true is " + new org.hamcrest.StringDescription().appendValue(true).toString() + "\n", _should_be);50 51 boolean _should_be_1 = Should.<Integer>should_be(52 Integer.valueOf((1 + 1)), Integer.valueOf(1));53 Assert.assertFalse("\nExpected 1 + 1 should not be 1 but"54 + "\n 1 + 1 is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf((1 + 1))).toString() + "\n", _should_be_1);55 56 Assert.assertNotNull("\nExpected \"something\" should not be null\n but is " + new org.hamcrest.StringDescription().appendValue("something").toString() + "\n", "something");57 58 boolean _doubleArrow = Should.<Integer>operator_doubleArrow(59 Integer.valueOf((1 + 1)), Integer.valueOf(2));60 Assert.assertTrue("\nExpected 1 + 1 => 2 but"61 + "\n 1 + 1 is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf((1 + 1))).toString() + "\n", _doubleArrow);62 63 boolean _doubleArrow_1 = Should.operator_doubleArrow(64 "a string", String.class);65 Assert.assertTrue("\nExpected // types\r\n \"a string\" => typeof(String) but"66 + "\n // types\r\n \"a string\" => typeof(String) is " + new org.hamcrest.StringDescription().appendValue(_doubleArrow_1).toString() + "\n", _doubleArrow_1);67 68 Class<? extends String> _class = "a string".getClass();69 boolean _doubleArrow_2 = Should.operator_doubleArrow(_class, String.class);70 Assert.assertTrue("\nExpected \"a string\".getClass => typeof(String) but"71 + "\n \"a string\".getClass is " + new org.hamcrest.StringDescription().appendValue(_class).toString() + "\n", _doubleArrow_2);72 73 boolean _should_contain = Should.<Object>should_contain(74 "something", "thing");75 Assert.assertTrue("\nExpected // strings\r\n \"something\" should contain \"thing\" but"76 + "\n // strings\r\n \"something\" should contain \"thing\" is " + new org.hamcrest.StringDescription().appendValue(true).toString() + "\n", _should_contain);77 78 boolean _should_contain_1 = Should.<Object>should_contain(79 "something", "any");80 Assert.assertFalse("\nExpected \"something\" should not contain \"any\" but"81 + "\n \"something\" should not contain \"any\" is " + new org.hamcrest.StringDescription().appendValue(true).toString() + "\n", _should_contain_1);82 83 List<String> _list = JnarioCollectionLiterals.<String>list("something");84 boolean _should_contain_2 = Should.<String>should_contain(_list, "something");85 Assert.assertTrue("\nExpected // iterables\r\n list(\"something\") should contain \"something\" but"86 + "\n // iterables\r\n list(\"something\") is " + new org.hamcrest.StringDescription().appendValue(_list).toString() + "\n", _should_contain_2);87 88 List<String> _list_1 = JnarioCollectionLiterals.<String>list("something");89 boolean _should_contain_3 = Should.<String>should_contain(_list_1, "something else");90 Assert.assertFalse("\nExpected list(\"something\") should not contain \"something else\" but"91 + "\n list(\"something\") is " + new org.hamcrest.StringDescription().appendValue(_list_1).toString() + "\n", _should_contain_3);92 93 final Procedure1<String> _function = new Procedure1<String>() {94 public void apply(final String it) {95 int _length = it.length();96 boolean _doubleArrow = Should.<Integer>operator_doubleArrow(Integer.valueOf(_length), Integer.valueOf(11));97 Assert.assertTrue("\nExpected length => 11 but"98 + "\n length is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(_length)).toString() + "\n", _doubleArrow);99 100 boolean _should_startWith = Should.should_startWith(it, "hello");101 Assert.assertTrue("\nExpected it should startWith(\"hello\") but"102 + "\n it is " + new org.hamcrest.StringDescription().appendValue(it).toString() + "\n", _should_startWith);103 104 Assert.assertTrue("\nExpected it should endWith(\"world\") but"105 + "\n it is " + new org.hamcrest.StringDescription().appendValue(it).toString() + "\n", Should.should_endWith(it, "world"));106 107 }108 };109 final String greeting = ObjectExtensions.<String>operator_doubleArrow("hello world", _function);110 boolean _doubleArrow_3 = Should.operator_doubleArrow(greeting, String.class);111 Assert.assertTrue("\nExpected greeting => typeof(String) but"112 + "\n greeting is " + new org.hamcrest.StringDescription().appendValue(greeting).toString() + "\n", _doubleArrow_3);113 114 boolean expectedException = false;115 String message = "";116 try{117 Stack<String> _stack = new Stack<String>();118 _stack.pop();119 message = "Expected " + EmptyStackException.class.getName() + " for \n // expecting exceptions\r\n new Stack<String>().pop\n with:"120 + "\n // expecting exceptions\r\n new Stack<String>() is " + new org.hamcrest.StringDescription().appendValue(_stack).toString();121 }catch(EmptyStackException e){122 expectedException = true;123 }124 Assert.assertTrue(message, expectedException);125 boolean expectedException_1 = false;126 String message_1 = "";127 try{128 Stack<String> _stack_1 = new Stack<String>();129 _stack_1.pop();130 message_1 = "Expected " + EmptyStackException.class.getName() + " for \n new Stack<String>().pop\n with:"131 + "\n new Stack<String>() is " + new org.hamcrest.StringDescription().appendValue(_stack_1).toString();132 }catch(EmptyStackException e){133 expectedException_1 = true;134 }135 Assert.assertTrue(message_1, expectedException_1);136 }137 138 /**139 * `should` throws an AssertionError if the result of the left140 * expression does not equal the result of the right expression.141 * Here is a helper method we are going to use:142 * 143 * <pre class="prettyprint lang-spec">144 * def void method(){145 * throw new IllegalArgumentException146 * }147 * </pre>148 * 149 * ...and here are the examples:150 */151 @Test152 @Named("...or not to pass")153 @Order(2)154 public void _orNotToPass() throws Exception {155 boolean expectedException = false;156 String message = "";157 try{158 boolean _should_be = Should.<Integer>should_be(159 Integer.valueOf((1 + 1)), Integer.valueOf(1));160 Assert.assertTrue("\nExpected 1 + 1 should be 1 but"161 + "\n 1 + 1 is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf((1 + 1))).toString() + "\n", _should_be);162 163 message = "Expected " + AssertionError.class.getName() + " for \n 1 + 1 should be 1\n with:"164 + "\n 1 + 1 is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf((1 + 1))).toString();165 }catch(AssertionError e){166 expectedException = true;167 }168 Assert.assertTrue(message, expectedException);169 boolean expectedException_1 = false;170 String message_1 = "";171 try{172 boolean _should_be_1 = Should.<Integer>should_be(173 Integer.valueOf((1 + 1)), Integer.valueOf(2));174 Assert.assertFalse("\nExpected 1 + 1 should not be 2 but"175 + "\n 1 + 1 is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf((1 + 1))).toString() + "\n", _should_be_1);176 177 message_1 = "Expected " + AssertionError.class.getName() + " for \n 1 + 1 should not be 2\n with:"178 + "\n 1 + 1 is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf((1 + 1))).toString();179 }catch(AssertionError e){180 expectedException_1 = true;181 }182 Assert.assertTrue(message_1, expectedException_1);183 boolean expectedException_2 = false;184 String message_2 = "";185 try{186 boolean _doubleArrow = Should.<Integer>operator_doubleArrow(187 Integer.valueOf((1 + 1)), Integer.valueOf(1));188 Assert.assertTrue("\nExpected 1 + 1 => 1 but"189 + "\n 1 + 1 is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf((1 + 1))).toString() + "\n", _doubleArrow);190 191 message_2 = "Expected " + AssertionError.class.getName() + " for \n 1 + 1 => 1\n with:"192 + "\n 1 + 1 is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf((1 + 1))).toString();193 }catch(AssertionError e){194 expectedException_2 = true;195 }196 Assert.assertTrue(message_2, expectedException_2);197 boolean expectedException_3 = false;198 String message_3 = "";199 try{200 Object _object = new Object();201 Assert.assertNull("\nExpected new Object => null\n but is " + new org.hamcrest.StringDescription().appendValue(_object).toString() + "\n", _object);202 203 message_3 = "Expected " + AssertionError.class.getName() + " for \n new Object => null\n with:"204 + "\n new Object is " + new org.hamcrest.StringDescription().appendValue(_object).toString();205 }catch(AssertionError e){206 expectedException_3 = true;207 }208 Assert.assertTrue(message_3, expectedException_3);209 boolean expectedException_4 = false;210 String message_4 = "";211 try{212 Object _object_1 = new Object();213 Assert.assertNull("\nExpected new Object should be null\n but is " + new org.hamcrest.StringDescription().appendValue(_object_1).toString() + "\n", _object_1);214 215 message_4 = "Expected " + AssertionError.class.getName() + " for \n new Object should be null\n with:"216 + "\n new Object is " + new org.hamcrest.StringDescription().appendValue(_object_1).toString();217 }catch(AssertionError e){218 expectedException_4 = true;219 }220 Assert.assertTrue(message_4, expectedException_4);221 boolean expectedException_5 = false;222 String message_5 = "";223 try{224 this.method();225 message_5 = "Expected " + IllegalArgumentException.class.getName() + " for \n method()\n with:";226 }catch(IllegalArgumentException e){227 expectedException_5 = true;228 }229 Assert.assertTrue(message_5, expectedException_5);230 }231 232 public void method() {233 throw new IllegalArgumentException();234 }235 236 /**237 * When failing, `should` and `=>` try to give you as much context information as possible.238 * The error message will print the values of all expressions and their subexpressions.239 */240 @Test241 @Named("Why did it fail?")242 @Order(3)243 public void _whyDidItFail() throws Exception {244 final Procedure1<Boolean> _function = new Procedure1<Boolean>() {245 public void apply(final Boolean it) {246 Assert.assertTrue("\nExpected 1 + 1 => 1 but"247 + "\n 1 + 1 is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf((1 + 1))).toString() + "\n", Should.<Integer>operator_doubleArrow(Integer.valueOf((1 + 1)), Integer.valueOf(1)));248 249 }250 };251 String _errorMessage = Helpers.errorMessage(_function);252 StringConcatenation _builder = new StringConcatenation();253 _builder.append("Expected 1 + 1 => 1 but");254 _builder.newLine();255 _builder.append(" ");256 _builder.append("1 + 1 is <2>");257 Helpers.is(_errorMessage, _builder);258 final String x = "hello";259 final Procedure1<Boolean> _function_1 = new Procedure1<Boolean>() {260 public void apply(final Boolean it) {261 String _upperCase = x.toUpperCase();262 Assert.assertFalse("\nExpected x.toUpperCase should not be \"HELLO\" but"263 + "\n x.toUpperCase is " + new org.hamcrest.StringDescription().appendValue(_upperCase).toString()264 + "\n x is " + new org.hamcrest.StringDescription().appendValue(x).toString() + "\n", Should.<String>should_be(_upperCase, "HELLO"));265 266 }267 };268 String _errorMessage_1 = Helpers.errorMessage(_function_1);269 StringConcatenation _builder_1 = new StringConcatenation();270 _builder_1.append("Expected x.toUpperCase should not be \"HELLO\" but");271 _builder_1.newLine();272 _builder_1.append(" ");273 _builder_1.append("x.toUpperCase is \"HELLO\"");274 _builder_1.newLine();275 _builder_1.append(" ");276 _builder_1.append("x is \"hello\"");277 Helpers.is(_errorMessage_1, _builder_1);278 final String y = "world";279 final Procedure1<Boolean> _function_2 = new Procedure1<Boolean>() {280 public void apply(final Boolean it) {281 Assert.assertTrue("\nExpected x => y but"282 + "\n x is " + new org.hamcrest.StringDescription().appendValue(x).toString()283 + "\n y is " + new org.hamcrest.StringDescription().appendValue(y).toString() + "\n", Should.<String>operator_doubleArrow(x, y));284 285 }286 };287 String _errorMessage_2 = Helpers.errorMessage(_function_2);288 StringConcatenation _builder_2 = new StringConcatenation();289 _builder_2.append("Expected x => y but");290 _builder_2.newLine();291 _builder_2.append(" ");292 _builder_2.append("x is \"hello\"");293 _builder_2.newLine();294 _builder_2.append(" ");295 _builder_2.append("y is \"world\"");296 Helpers.is(_errorMessage_2, _builder_2);297 }298 299 /**300 * This useful helper automatically waits until a condition turns true.301 * Expects a lambda expression returning a boolean value. The error message,302 * polling interval and duration are configurable.303 */304 @Test305 @Named("Wait for something")306 @Order(4)307 public void _waitForSomething() throws Exception {308 final Function1<Wait, Boolean> _function = new Function1<Wait, Boolean>() {309 public Boolean apply(final Wait it) {310 return Boolean.valueOf((1 > 0));311 }312 };313 Wait.waitUntil(_function);314 final Function1<Wait, Boolean> _function_1 = new Function1<Wait, Boolean>() {315 public Boolean apply(final Wait it) {316 boolean _xblockexpression = false;317 {318 it.setMessage("Custom error message");319 it.setDuration(100);320 it.setPollingInterval(10);321 _xblockexpression = (1 > 0);322 }323 return Boolean.valueOf(_xblockexpression);324 }325 };326 Wait.waitUntil(_function_1);327 }328 329 /**330 * You can also define your own *should* matchers by331 * defining a method with the prefix *should_XXXX* in332 * the current scope. The method needs to return a boolean333 * value. For example, when we define334 * a method *should_eat*:335 * 336 * def should_eat(String animal, String food){337 * animal == "Monkey" && food == "Banana"338 * }339 * 340 * We can use "eat" in our should expressions:341 */342 @Test343 @Named("Define your own matchers")344 @Order(5)345 public void _defineYourOwnMatchers() throws Exception {346 boolean _should_eat = this.should_eat(347 "Monkey", "Banana");348 Assert.assertTrue("\nExpected \"Monkey\" should eat \"Banana\" but" + " did not." + "\n", _should_eat);349 350 boolean expectedException = false;351 String message = "";352 try{353 boolean _should_eat_1 = this.should_eat(354 "Monkey", "Rocks");355 Assert.assertTrue("\nExpected \"Monkey\" should eat \"Rocks\" but" + " did not." + "\n", _should_eat_1);356 357 message = "Expected " + AssertionError.class.getName() + " for \n \"Monkey\" should eat \"Rocks\"\n with:";358 }catch(AssertionError e){359 expectedException = true;360 }361 Assert.assertTrue(message, expectedException);362 }363 364 public boolean should_eat(final String animal, final String food) {365 boolean _and = false;366 boolean _equals = Objects.equal(animal, "Monkey");367 if (!_equals) {368 _and = false;369 } else {370 boolean _equals_1 = Objects.equal(food, "Banana");371 _and = _equals_1;372 }373 return _and;374 }375 376 /**377 * You can also the `should` and `=>` together with [hamcrest](http://code.google.com/p/hamcrest/)378 * matchers. The following static import statements are needed to run the examples:379 * 380 * import static org.hamcrest.CoreMatchers.startsWith381 * import static org.hamcrest.CoreMatchers.equalTo382 * 383 * If the right-hand side of a should expression is a matcher, the matcher will be evaluated instead384 * of testing for equality:385 */386 @Test387 @Named("Combining hamcrest and should")388 @Order(6)389 public void _combiningHamcrestAndShould() throws Exception {390 Matcher<String> _startsWith = Matchers.startsWith("h");391 boolean _doubleArrow = Should.<String>operator_doubleArrow(392 "hello", _startsWith);393 Assert.assertTrue("\nExpected \"hello\" => startsWith(\"h\") but"394 + "\n startsWith(\"h\") is " + new org.hamcrest.StringDescription().appendValue(_startsWith).toString() + "\n", _doubleArrow);395 396 Matcher<Integer> _greaterThan = Matchers.<Integer>greaterThan(Integer.valueOf(5));397 Assert.assertTrue("\nExpected 9 should be greaterThan(5) but"398 + "\n greaterThan(5) is " + new org.hamcrest.StringDescription().appendValue(_greaterThan).toString() + "\n", Should.<Integer>should_be(399 Integer.valueOf(9), _greaterThan));400 401 }402 403 /**404 * In order to be able to print the value of all subexpressions when an assertion failed,405 * we disabled the short circuit semantics of '&&' and '||' within assertions.406 */407 @Test408 @Named("Short Circuit Invocation")409 @Order(7)410 public void _shortCircuitInvocation() throws Exception {411 final String aString = null;412 boolean expectedException = false;413 String message = "";414 try{415 boolean _notEquals = (!Objects.equal(aString, null));416 int _length = aString.length();417 boolean _equals = (_length == 0);418 boolean _and = (_notEquals && _equals);419 Assert.assertTrue("\nExpected aString != null && aString.length == 0 but"420 + "\n aString != null is " + new org.hamcrest.StringDescription().appendValue(_notEquals).toString()421 + "\n aString is " + new org.hamcrest.StringDescription().appendValue(aString).toString()422 + "\n aString.length == 0 is " + new org.hamcrest.StringDescription().appendValue(_equals).toString()423 + "\n aString.length is " + new org.hamcrest.StringDescription().appendValue(_length).toString() + "\n", _and);424 425 message = "Expected " + NullPointerException.class.getName() + " for \n assert aString != null && aString.length == 0\n with:"426 + "\n aString != null && aString.length == 0 is " + new org.hamcrest.StringDescription().appendValue(_and).toString()427 + "\n aString != null is " + new org.hamcrest.StringDescription().appendValue(_notEquals).toString()428 + "\n aString is " + new org.hamcrest.StringDescription().appendValue(aString).toString()429 + "\n aString.length == 0 is " + new org.hamcrest.StringDescription().appendValue(_equals).toString()430 + "\n aString.length is " + new org.hamcrest.StringDescription().appendValue(_length).toString();431 }catch(NullPointerException e){432 expectedException = true;433 }434 Assert.assertTrue(message, expectedException);435 }436}...
Source:HashBasedSpec2ResultMappingExampleGroupSpec.java
...44 this.m.parseSpec(_builder);45 ExampleGroup _exampleGroup = this.m.exampleGroup("Root");46 SpecExecution _result = this.result(_exampleGroup);47 Assert.assertTrue("\nExpected m.exampleGroup(\"Root\").result => typeof(Pending) but"48 + "\n m.exampleGroup(\"Root\").result is " + new org.hamcrest.StringDescription().appendValue(_result).toString()49 + "\n m.exampleGroup(\"Root\") is " + new org.hamcrest.StringDescription().appendValue(_exampleGroup).toString()50 + "\n m is " + new org.hamcrest.StringDescription().appendValue(this.m).toString() + "\n", Should.operator_doubleArrow(_result, Pending.class));51 52 }53 54 @Test55 @Named("returns NotRun if children are not executed but have an implementation")56 @Order(2)57 public void _returnsNotRunIfChildrenAreNotExecutedButHaveAnImplementation() throws Exception {58 StringConcatenation _builder = new StringConcatenation();59 _builder.append("describe \"Root\"{");60 _builder.newLine();61 _builder.append("\t");62 _builder.append("fact \"fact 1\"{ \"with implementation\" }");63 _builder.newLine();64 _builder.append("\t");65 _builder.append("fact \"fact 2\"{ \"with implementation\" }");66 _builder.newLine();67 _builder.append("}");68 _builder.newLine();69 this.m.parseSpec(_builder);70 ExampleGroup _exampleGroup = this.m.exampleGroup("Root");71 SpecExecution _result = this.result(_exampleGroup);72 Assert.assertTrue("\nExpected m.exampleGroup(\"Root\").result => typeof(NotRun) but"73 + "\n m.exampleGroup(\"Root\").result is " + new org.hamcrest.StringDescription().appendValue(_result).toString()74 + "\n m.exampleGroup(\"Root\") is " + new org.hamcrest.StringDescription().appendValue(_exampleGroup).toString()75 + "\n m is " + new org.hamcrest.StringDescription().appendValue(this.m).toString() + "\n", Should.operator_doubleArrow(_result, NotRun.class));76 77 }78 79 @Test80 @Named("passes if all children pass")81 @Order(3)82 public void _passesIfAllChildrenPass() throws Exception {83 StringConcatenation _builder = new StringConcatenation();84 _builder.append("describe \"Root\"{");85 _builder.newLine();86 _builder.append("\t");87 _builder.append("fact \"Example 1\"{ \"with implementation\" }");88 _builder.newLine();89 _builder.append("\t");90 _builder.append("fact \"Example 2\"{ \"with implementation\" }");91 _builder.newLine();92 _builder.append("}");93 _builder.newLine();94 this.m.parseSpec(_builder);95 this.passes("Example 1", "Example 2");96 ExampleGroup _exampleGroup = this.m.exampleGroup("Root");97 SpecExecution _result = this.result(_exampleGroup);98 Assert.assertTrue("\nExpected m.exampleGroup(\"Root\").result => typeof(Passed) but"99 + "\n m.exampleGroup(\"Root\").result is " + new org.hamcrest.StringDescription().appendValue(_result).toString()100 + "\n m.exampleGroup(\"Root\") is " + new org.hamcrest.StringDescription().appendValue(_exampleGroup).toString()101 + "\n m is " + new org.hamcrest.StringDescription().appendValue(this.m).toString() + "\n", Should.operator_doubleArrow(_result, Passed.class));102 103 }104 105 @Test106 @Named("fails if one child has failed")107 @Order(4)108 public void _failsIfOneChildHasFailed() throws Exception {109 StringConcatenation _builder = new StringConcatenation();110 _builder.append("describe \"Root\"{");111 _builder.newLine();112 _builder.append("\t");113 _builder.append("fact \"Example 1\"{ \"with implementation\" }");114 _builder.newLine();115 _builder.append("\t");116 _builder.append("fact \"Example 2\"{ \"with implementation\" }");117 _builder.newLine();118 _builder.append("}");119 _builder.newLine();120 this.m.parseSpec(_builder);121 this.passes("Example 1");122 this.fails("Example 2");123 ExampleGroup _exampleGroup = this.m.exampleGroup("Root");124 SpecExecution _result = this.result(_exampleGroup);125 Assert.assertTrue("\nExpected m.exampleGroup(\"Root\").result => typeof(Failed) but"126 + "\n m.exampleGroup(\"Root\").result is " + new org.hamcrest.StringDescription().appendValue(_result).toString()127 + "\n m.exampleGroup(\"Root\") is " + new org.hamcrest.StringDescription().appendValue(_exampleGroup).toString()128 + "\n m is " + new org.hamcrest.StringDescription().appendValue(this.m).toString() + "\n", Should.operator_doubleArrow(_result, Failed.class));129 130 }131 132 @Test133 @Named("execution time is sum of all child examples")134 @Order(5)135 public void _executionTimeIsSumOfAllChildExamples() throws Exception {136 StringConcatenation _builder = new StringConcatenation();137 _builder.append("describe \"Root\"{");138 _builder.newLine();139 _builder.append("\t");140 _builder.append("fact \"Example 1\"{ \"with implementation\" }");141 _builder.newLine();142 _builder.append("\t");143 _builder.append("fact \"Example 2\"{ \"with implementation\" }");144 _builder.newLine();145 _builder.append("}");146 _builder.newLine();147 this.m.parseSpec(_builder);148 this.exampleExecutedIn("Example 1", 1.0);149 this.exampleExecutedIn("Example 2", 2.0);150 ExampleGroup _exampleGroup = this.m.exampleGroup("Root");151 SpecExecution _result = this.result(_exampleGroup);152 double _executionTimeInSeconds = _result.getExecutionTimeInSeconds();153 Assert.assertTrue("\nExpected m.exampleGroup(\"Root\").result.executionTimeInSeconds => 3.0 but"154 + "\n m.exampleGroup(\"Root\").result.executionTimeInSeconds is " + new org.hamcrest.StringDescription().appendValue(Double.valueOf(_executionTimeInSeconds)).toString()155 + "\n m.exampleGroup(\"Root\").result is " + new org.hamcrest.StringDescription().appendValue(_result).toString()156 + "\n m.exampleGroup(\"Root\") is " + new org.hamcrest.StringDescription().appendValue(_exampleGroup).toString()157 + "\n m is " + new org.hamcrest.StringDescription().appendValue(this.m).toString() + "\n", Should.<Double>operator_doubleArrow(Double.valueOf(_executionTimeInSeconds), Double.valueOf(3.0)));158 159 }160 161 @Test162 @Named("class name is from spec")163 @Order(6)164 public void _classNameIsFromSpec() throws Exception {165 StringConcatenation _builder = new StringConcatenation();166 _builder.append("describe \"Root\"{");167 _builder.newLine();168 _builder.append("\t");169 _builder.append("fact \"Example 1\"{ \"with implementation\" }");170 _builder.newLine();171 _builder.append("\t");172 _builder.append("fact \"Example 2\"{ \"with implementation\" }");173 _builder.newLine();174 _builder.append("}");175 _builder.newLine();176 this.m.parseSpec(_builder);177 this.passes("Example 1");178 ExampleGroup _exampleGroup = this.m.exampleGroup("Root");179 SpecExecution _result = this.result(_exampleGroup);180 String _className = _result.getClassName();181 Assert.assertTrue("\nExpected m.exampleGroup(\"Root\").result.className => \"RootSpec\" but"182 + "\n m.exampleGroup(\"Root\").result.className is " + new org.hamcrest.StringDescription().appendValue(_className).toString()183 + "\n m.exampleGroup(\"Root\").result is " + new org.hamcrest.StringDescription().appendValue(_result).toString()184 + "\n m.exampleGroup(\"Root\") is " + new org.hamcrest.StringDescription().appendValue(_exampleGroup).toString()185 + "\n m is " + new org.hamcrest.StringDescription().appendValue(this.m).toString() + "\n", Should.<String>operator_doubleArrow(_className, "RootSpec"));186 187 }188 189 @Test190 @Named("name is from spec")191 @Order(7)192 public void _nameIsFromSpec() throws Exception {193 StringConcatenation _builder = new StringConcatenation();194 _builder.append("describe \"Root\"{");195 _builder.newLine();196 _builder.append("\t");197 _builder.append("fact \"Example 1\"");198 _builder.newLine();199 _builder.append("\t");200 _builder.append("fact \"Example 2\"");201 _builder.newLine();202 _builder.append("}");203 _builder.newLine();204 this.m.parseSpec(_builder);205 this.passes("Example 1");206 ExampleGroup _exampleGroup = this.m.exampleGroup("Root");207 SpecExecution _result = this.result(_exampleGroup);208 String _name = _result.getName();209 Assert.assertTrue("\nExpected m.exampleGroup(\"Root\").result.name => \"Root\" but"210 + "\n m.exampleGroup(\"Root\").result.name is " + new org.hamcrest.StringDescription().appendValue(_name).toString()211 + "\n m.exampleGroup(\"Root\").result is " + new org.hamcrest.StringDescription().appendValue(_result).toString()212 + "\n m.exampleGroup(\"Root\") is " + new org.hamcrest.StringDescription().appendValue(_exampleGroup).toString()213 + "\n m is " + new org.hamcrest.StringDescription().appendValue(this.m).toString() + "\n", Should.<String>operator_doubleArrow(_name, "Root"));214 215 }216 217 @Test218 @Named("caches calculated results")219 @Order(8)220 public void _cachesCalculatedResults() throws Exception {221 StringConcatenation _builder = new StringConcatenation();222 _builder.append("describe \"Root\"{");223 _builder.newLine();224 _builder.append("\t");225 _builder.append("fact \"Example 1\"");226 _builder.newLine();227 _builder.append("\t");228 _builder.append("fact \"Example 2\"");229 _builder.newLine();230 _builder.append("}");231 _builder.newLine();232 this.m.parseSpec(_builder);233 this.passes("Example 1");234 final ExampleGroup exampleGroup = this.m.exampleGroup("Root");235 final SpecExecution first = this.result(exampleGroup);236 final SpecExecution second = this.result(exampleGroup);237 Matcher<SpecExecution> _sameInstance = CoreMatchers.<SpecExecution>sameInstance(second);238 Assert.assertTrue("\nExpected first => sameInstance(second) but"239 + "\n first is " + new org.hamcrest.StringDescription().appendValue(first).toString()240 + "\n sameInstance(second) is " + new org.hamcrest.StringDescription().appendValue(_sameInstance).toString()241 + "\n second is " + new org.hamcrest.StringDescription().appendValue(second).toString() + "\n", Should.<SpecExecution>operator_doubleArrow(first, _sameInstance));242 243 }244 245 @Test246 @Named("supports nested specs")247 @Order(9)248 public void _supportsNestedSpecs() throws Exception {249 StringConcatenation _builder = new StringConcatenation();250 _builder.append("describe \"Root\"{");251 _builder.newLine();252 _builder.append("\t");253 _builder.append("describe \"Child\"{");254 _builder.newLine();255 _builder.append("\t\t");256 _builder.append("fact \"Example 1\"{1 + 1 => 2}");257 _builder.newLine();258 _builder.append("\t");259 _builder.append("}\t");260 _builder.newLine();261 _builder.append("}");262 _builder.newLine();263 this.m.parseSpec(_builder);264 HashBasedSpec2ResultMappingExampleGroupSpec.CLASSNAME = "RootChildSpec";265 this.passes("Example 1");266 ExampleGroup _exampleGroup = this.m.exampleGroup("Root");267 SpecExecution _result = this.result(_exampleGroup);268 Assert.assertTrue("\nExpected m.exampleGroup(\"Root\").result => typeof(Passed) but"269 + "\n m.exampleGroup(\"Root\").result is " + new org.hamcrest.StringDescription().appendValue(_result).toString()270 + "\n m.exampleGroup(\"Root\") is " + new org.hamcrest.StringDescription().appendValue(_exampleGroup).toString()271 + "\n m is " + new org.hamcrest.StringDescription().appendValue(this.m).toString() + "\n", Should.operator_doubleArrow(_result, Passed.class));272 273 }274 275 @Test276 @Ignore277 @Named("supports nested specs referencing methods [PENDING]")278 @Order(10)279 public void _supportsNestedSpecsReferencingMethods() throws Exception {280 StringConcatenation _builder = new StringConcatenation();281 _builder.append("describe String{");282 _builder.newLine();283 _builder.append("\t");284 _builder.append("describe charAt{");285 _builder.newLine();286 _builder.append("\t\t");287 _builder.append("fact \"Example 1\"{1 + 1 => 2}");288 _builder.newLine();289 _builder.append("\t");290 _builder.append("}\t");291 _builder.newLine();292 _builder.append("}");293 _builder.newLine();294 this.m.parseSpec(_builder);295 HashBasedSpec2ResultMappingExampleGroupSpec.CLASSNAME = "RootCharAtSpec";296 this.passes("Example 1");297 ExampleGroup _exampleGroup = this.m.exampleGroup("String");298 SpecExecution _result = this.result(_exampleGroup);299 Assert.assertTrue("\nExpected m.exampleGroup(\"String\").result => typeof(Passed) but"300 + "\n m.exampleGroup(\"String\").result is " + new org.hamcrest.StringDescription().appendValue(_result).toString()301 + "\n m.exampleGroup(\"String\") is " + new org.hamcrest.StringDescription().appendValue(_exampleGroup).toString()302 + "\n m is " + new org.hamcrest.StringDescription().appendValue(this.m).toString() + "\n", Should.operator_doubleArrow(_result, Passed.class));303 304 }305 306 public void exampleExecutedIn(final String name, final double time) {307 Passed _passingSpec = Passed.passingSpec(HashBasedSpec2ResultMappingExampleGroupSpec.CLASSNAME, name, time);308 this.subject.accept(_passingSpec);309 }310 311 public void fails(final String name) {312 Failed _failingSpec = Failed.failingSpec(HashBasedSpec2ResultMappingExampleGroupSpec.CLASSNAME, name, HashBasedSpec2ResultMappingSpec.anyExecutionTime, this.anyFailure);313 this.subject.accept(_failingSpec);314 }315 316 public void passes(final String... names) {...
Source:ExtensionLibraryIterableIteratorHelpersSpec.java
...41 final List<Integer> values = JnarioCollectionLiterals.<Integer>list(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4), Integer.valueOf(5));42 Integer _first = JnarioIterableExtensions.<Integer>first(values);43 boolean _doubleArrow = Should.<Integer>operator_doubleArrow(_first, Integer.valueOf(1));44 Assert.assertTrue("\nExpected values.first => 1 but"45 + "\n values.first is " + new org.hamcrest.StringDescription().appendValue(_first).toString()46 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow);47 48 Integer _last = IterableExtensions.<Integer>last(values);49 boolean _doubleArrow_1 = Should.<Integer>operator_doubleArrow(_last, Integer.valueOf(5));50 Assert.assertTrue("\nExpected values.last => 5 but"51 + "\n values.last is " + new org.hamcrest.StringDescription().appendValue(_last).toString()52 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow_1);53 54 Integer _second = JnarioIterableExtensions.<Integer>second(values);55 boolean _doubleArrow_2 = Should.<Integer>operator_doubleArrow(_second, Integer.valueOf(2));56 Assert.assertTrue("\nExpected values.second => 2 but"57 + "\n values.second is " + new org.hamcrest.StringDescription().appendValue(_second).toString()58 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow_2);59 60 Integer _third = JnarioIterableExtensions.<Integer>third(values);61 boolean _doubleArrow_3 = Should.<Integer>operator_doubleArrow(_third, Integer.valueOf(3));62 Assert.assertTrue("\nExpected values.third => 3 but"63 + "\n values.third is " + new org.hamcrest.StringDescription().appendValue(_third).toString()64 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow_3);65 66 Integer _forth = JnarioIterableExtensions.<Integer>forth(values);67 boolean _doubleArrow_4 = Should.<Integer>operator_doubleArrow(_forth, Integer.valueOf(4));68 Assert.assertTrue("\nExpected values.forth => 4 but"69 + "\n values.forth is " + new org.hamcrest.StringDescription().appendValue(_forth).toString()70 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow_4);71 72 Integer _fifth = JnarioIterableExtensions.<Integer>fifth(values);73 boolean _doubleArrow_5 = Should.<Integer>operator_doubleArrow(_fifth, Integer.valueOf(5));74 Assert.assertTrue("\nExpected values.fifth => 5 but"75 + "\n values.fifth is " + new org.hamcrest.StringDescription().appendValue(_fifth).toString()76 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow_5);77 78 Integer _get = values.get(3);79 boolean _doubleArrow_6 = Should.<Integer>operator_doubleArrow(_get, Integer.valueOf(4));80 Assert.assertTrue("\nExpected values.get(3) => 4 but"81 + "\n values.get(3) is " + new org.hamcrest.StringDescription().appendValue(_get).toString()82 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow_6);83 84 final List<Object> objects = JnarioCollectionLiterals.<Object>list(Integer.valueOf(1), "string", Boolean.valueOf(true), "other string");85 String _first_1 = JnarioIterableExtensions.<String>first(objects, String.class);86 boolean _doubleArrow_7 = Should.<String>operator_doubleArrow(_first_1, "string");87 Assert.assertTrue("\nExpected objects.first(typeof(String)) => \"string\" but"88 + "\n objects.first(typeof(String)) is " + new org.hamcrest.StringDescription().appendValue(_first_1).toString()89 + "\n objects is " + new org.hamcrest.StringDescription().appendValue(objects).toString() + "\n", _doubleArrow_7);90 91 String _second_1 = JnarioIterableExtensions.<String>second(objects, String.class);92 Assert.assertTrue("\nExpected objects.second(typeof(String)) => \"other string\" but"93 + "\n objects.second(typeof(String)) is " + new org.hamcrest.StringDescription().appendValue(_second_1).toString()94 + "\n objects is " + new org.hamcrest.StringDescription().appendValue(objects).toString() + "\n", Should.<String>operator_doubleArrow(_second_1, "other string"));95 96 }97 98 /**99 * These methods work also for iterators. Note100 * that calling one of these methods will consume101 * the iterator to the position of the returned element.102 */103 @Test104 @Named("Iterators")105 @Order(2)106 public void _iterators() throws Exception {107 final List<Integer> values = JnarioCollectionLiterals.<Integer>list(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4), Integer.valueOf(5));108 Iterator<Integer> _iterator = values.iterator();109 Integer _first = JnarioIteratorExtensions.<Integer>first(_iterator);110 boolean _doubleArrow = Should.<Integer>operator_doubleArrow(_first, Integer.valueOf(1));111 Assert.assertTrue("\nExpected values.iterator.first => 1 but"112 + "\n values.iterator.first is " + new org.hamcrest.StringDescription().appendValue(_first).toString()113 + "\n values.iterator is " + new org.hamcrest.StringDescription().appendValue(_iterator).toString()114 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow);115 116 Iterator<Integer> _iterator_1 = values.iterator();117 Integer _last = IteratorExtensions.<Integer>last(_iterator_1);118 boolean _doubleArrow_1 = Should.<Integer>operator_doubleArrow(_last, Integer.valueOf(5));119 Assert.assertTrue("\nExpected values.iterator.last => 5 but"120 + "\n values.iterator.last is " + new org.hamcrest.StringDescription().appendValue(_last).toString()121 + "\n values.iterator is " + new org.hamcrest.StringDescription().appendValue(_iterator_1).toString()122 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow_1);123 124 Iterator<Integer> _iterator_2 = values.iterator();125 Integer _get = JnarioIteratorExtensions.<Integer>get(_iterator_2, 3);126 boolean _doubleArrow_2 = Should.<Integer>operator_doubleArrow(_get, Integer.valueOf(4));127 Assert.assertTrue("\nExpected values.iterator.get(3) => 4 but"128 + "\n values.iterator.get(3) is " + new org.hamcrest.StringDescription().appendValue(_get).toString()129 + "\n values.iterator is " + new org.hamcrest.StringDescription().appendValue(_iterator_2).toString()130 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow_2);131 132 Iterator<Integer> _iterator_3 = values.iterator();133 Integer _second = JnarioIteratorExtensions.<Integer>second(_iterator_3);134 boolean _doubleArrow_3 = Should.<Integer>operator_doubleArrow(_second, Integer.valueOf(2));135 Assert.assertTrue("\nExpected values.iterator.second => 2 but"136 + "\n values.iterator.second is " + new org.hamcrest.StringDescription().appendValue(_second).toString()137 + "\n values.iterator is " + new org.hamcrest.StringDescription().appendValue(_iterator_3).toString()138 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow_3);139 140 Iterator<Integer> _iterator_4 = values.iterator();141 Integer _third = JnarioIteratorExtensions.<Integer>third(_iterator_4);142 boolean _doubleArrow_4 = Should.<Integer>operator_doubleArrow(_third, Integer.valueOf(3));143 Assert.assertTrue("\nExpected values.iterator.third => 3 but"144 + "\n values.iterator.third is " + new org.hamcrest.StringDescription().appendValue(_third).toString()145 + "\n values.iterator is " + new org.hamcrest.StringDescription().appendValue(_iterator_4).toString()146 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow_4);147 148 Iterator<Integer> _iterator_5 = values.iterator();149 Integer _forth = JnarioIteratorExtensions.<Integer>forth(_iterator_5);150 boolean _doubleArrow_5 = Should.<Integer>operator_doubleArrow(_forth, Integer.valueOf(4));151 Assert.assertTrue("\nExpected values.iterator.forth => 4 but"152 + "\n values.iterator.forth is " + new org.hamcrest.StringDescription().appendValue(_forth).toString()153 + "\n values.iterator is " + new org.hamcrest.StringDescription().appendValue(_iterator_5).toString()154 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow_5);155 156 Iterator<Integer> _iterator_6 = values.iterator();157 Integer _fifth = JnarioIteratorExtensions.<Integer>fifth(_iterator_6);158 boolean _doubleArrow_6 = Should.<Integer>operator_doubleArrow(_fifth, Integer.valueOf(5));159 Assert.assertTrue("\nExpected values.iterator.fifth => 5 but"160 + "\n values.iterator.fifth is " + new org.hamcrest.StringDescription().appendValue(_fifth).toString()161 + "\n values.iterator is " + new org.hamcrest.StringDescription().appendValue(_iterator_6).toString()162 + "\n values is " + new org.hamcrest.StringDescription().appendValue(values).toString() + "\n", _doubleArrow_6);163 164 final List<Object> objects = JnarioCollectionLiterals.<Object>list(Integer.valueOf(1), "string", Boolean.valueOf(true), "other string");165 Iterator<Object> _iterator_7 = objects.iterator();166 String _first_1 = JnarioIteratorExtensions.<String>first(_iterator_7, String.class);167 boolean _doubleArrow_7 = Should.<String>operator_doubleArrow(_first_1, "string");168 Assert.assertTrue("\nExpected objects.iterator.first(typeof(String)) => \"string\" but"169 + "\n objects.iterator.first(typeof(String)) is " + new org.hamcrest.StringDescription().appendValue(_first_1).toString()170 + "\n objects.iterator is " + new org.hamcrest.StringDescription().appendValue(_iterator_7).toString()171 + "\n objects is " + new org.hamcrest.StringDescription().appendValue(objects).toString() + "\n", _doubleArrow_7);172 173 Iterator<Object> _iterator_8 = objects.iterator();174 String _second_1 = JnarioIteratorExtensions.<String>second(_iterator_8, String.class);175 Assert.assertTrue("\nExpected objects.iterator.second(typeof(String)) => \"other string\" but"176 + "\n objects.iterator.second(typeof(String)) is " + new org.hamcrest.StringDescription().appendValue(_second_1).toString()177 + "\n objects.iterator is " + new org.hamcrest.StringDescription().appendValue(_iterator_8).toString()178 + "\n objects is " + new org.hamcrest.StringDescription().appendValue(objects).toString() + "\n", Should.<String>operator_doubleArrow(_second_1, "other string"));179 180 }181}...
Source:ExecutableIsPendingFeatureSpec.java
...29 Feature _feature = Features.feature("Without scenarios and without background");30 boolean _isPending = _feature.isPending();31 boolean _should_be = Should.<Boolean>should_be(Boolean.valueOf(_isPending), true);32 Assert.assertTrue("\nExpected feature(\"Without scenarios and without background\").isPending() should be true but"33 + "\n feature(\"Without scenarios and without background\").isPending() is " + new org.hamcrest.StringDescription().appendValue(Boolean.valueOf(_isPending)).toString()34 + "\n feature(\"Without scenarios and without background\") is " + new org.hamcrest.StringDescription().appendValue(_feature).toString() + "\n", _should_be);35 36 }37 38 @Test39 @Named("featureWith[implementedScenario].isPending[] should be false")40 @Order(2)41 public void _featureWithImplementedScenarioIsPendingShouldBeFalse() throws Exception {42 Scenario _implementedScenario = Features.implementedScenario();43 Feature _featureWith = Features.featureWith(_implementedScenario);44 boolean _isPending = _featureWith.isPending();45 boolean _should_be = Should.<Boolean>should_be(Boolean.valueOf(_isPending), false);46 Assert.assertTrue("\nExpected featureWith(implementedScenario).isPending() should be false but"47 + "\n featureWith(implementedScenario).isPending() is " + new org.hamcrest.StringDescription().appendValue(Boolean.valueOf(_isPending)).toString()48 + "\n featureWith(implementedScenario) is " + new org.hamcrest.StringDescription().appendValue(_featureWith).toString()49 + "\n implementedScenario is " + new org.hamcrest.StringDescription().appendValue(_implementedScenario).toString() + "\n", _should_be);50 51 }52 53 @Test54 @Named("featureWith[scenarioWithoutSteps, implementedScenario].isPending[] should be true")55 @Order(3)56 public void _featureWithScenarioWithoutStepsImplementedScenarioIsPendingShouldBeTrue() throws Exception {57 Scenario _scenarioWithoutSteps = Features.scenarioWithoutSteps();58 Scenario _implementedScenario = Features.implementedScenario();59 Feature _featureWith = Features.featureWith(_scenarioWithoutSteps, _implementedScenario);60 boolean _isPending = _featureWith.isPending();61 boolean _should_be = Should.<Boolean>should_be(Boolean.valueOf(_isPending), true);62 Assert.assertTrue("\nExpected featureWith(scenarioWithoutSteps, implementedScenario).isPending() should be true but"63 + "\n featureWith(scenarioWithoutSteps, implementedScenario).isPending() is " + new org.hamcrest.StringDescription().appendValue(Boolean.valueOf(_isPending)).toString()64 + "\n featureWith(scenarioWithoutSteps, implementedScenario) is " + new org.hamcrest.StringDescription().appendValue(_featureWith).toString()65 + "\n scenarioWithoutSteps is " + new org.hamcrest.StringDescription().appendValue(_scenarioWithoutSteps).toString()66 + "\n implementedScenario is " + new org.hamcrest.StringDescription().appendValue(_implementedScenario).toString() + "\n", _should_be);67 68 }69 70 @Test71 @Named("featureWithBackground[implementedBackground].isPending[] should be true")72 @Order(4)73 public void _featureWithBackgroundImplementedBackgroundIsPendingShouldBeTrue() throws Exception {74 Background _implementedBackground = Features.implementedBackground();75 Feature _featureWithBackground = Features.featureWithBackground(_implementedBackground);76 boolean _isPending = _featureWithBackground.isPending();77 boolean _should_be = Should.<Boolean>should_be(Boolean.valueOf(_isPending), true);78 Assert.assertTrue("\nExpected featureWithBackground(implementedBackground).isPending() should be true but"79 + "\n featureWithBackground(implementedBackground).isPending() is " + new org.hamcrest.StringDescription().appendValue(Boolean.valueOf(_isPending)).toString()80 + "\n featureWithBackground(implementedBackground) is " + new org.hamcrest.StringDescription().appendValue(_featureWithBackground).toString()81 + "\n implementedBackground is " + new org.hamcrest.StringDescription().appendValue(_implementedBackground).toString() + "\n", _should_be);82 83 }84 85 @Test86 @Named("featureWithBackground[backgroundWithoutSteps].isPending[] should be true")87 @Order(5)88 public void _featureWithBackgroundBackgroundWithoutStepsIsPendingShouldBeTrue() throws Exception {89 Background _backgroundWithoutSteps = Features.backgroundWithoutSteps();90 Feature _featureWithBackground = Features.featureWithBackground(_backgroundWithoutSteps);91 boolean _isPending = _featureWithBackground.isPending();92 boolean _should_be = Should.<Boolean>should_be(Boolean.valueOf(_isPending), true);93 Assert.assertTrue("\nExpected featureWithBackground(backgroundWithoutSteps).isPending() should be true but"94 + "\n featureWithBackground(backgroundWithoutSteps).isPending() is " + new org.hamcrest.StringDescription().appendValue(Boolean.valueOf(_isPending)).toString()95 + "\n featureWithBackground(backgroundWithoutSteps) is " + new org.hamcrest.StringDescription().appendValue(_featureWithBackground).toString()96 + "\n backgroundWithoutSteps is " + new org.hamcrest.StringDescription().appendValue(_backgroundWithoutSteps).toString() + "\n", _should_be);97 98 }99 100 @Test101 @Named("featureWithBackgroundAndScenario[backgroundWithoutSteps, implementedScenario].isPending[] should be true")102 @Order(6)103 public void _featureWithBackgroundAndScenarioBackgroundWithoutStepsImplementedScenarioIsPendingShouldBeTrue() throws Exception {104 Background _backgroundWithoutSteps = Features.backgroundWithoutSteps();105 Scenario _implementedScenario = Features.implementedScenario();106 Feature _featureWithBackgroundAndScenario = Features.featureWithBackgroundAndScenario(_backgroundWithoutSteps, _implementedScenario);107 boolean _isPending = _featureWithBackgroundAndScenario.isPending();108 boolean _should_be = Should.<Boolean>should_be(Boolean.valueOf(_isPending), true);109 Assert.assertTrue("\nExpected featureWithBackgroundAndScenario(backgroundWithoutSteps, implementedScenario).isPending() should be true but"110 + "\n featureWithBackgroundAndScenario(backgroundWithoutSteps, implementedScenario).isPending() is " + new org.hamcrest.StringDescription().appendValue(Boolean.valueOf(_isPending)).toString()111 + "\n featureWithBackgroundAndScenario(backgroundWithoutSteps, implementedScenario) is " + new org.hamcrest.StringDescription().appendValue(_featureWithBackgroundAndScenario).toString()112 + "\n backgroundWithoutSteps is " + new org.hamcrest.StringDescription().appendValue(_backgroundWithoutSteps).toString()113 + "\n implementedScenario is " + new org.hamcrest.StringDescription().appendValue(_implementedScenario).toString() + "\n", _should_be);114 115 }116 117 @Test118 @Named("featureWithBackgroundAndScenario[implementedBackground, implementedScenario].isPending[] should be false")119 @Order(7)120 public void _featureWithBackgroundAndScenarioImplementedBackgroundImplementedScenarioIsPendingShouldBeFalse() throws Exception {121 Background _implementedBackground = Features.implementedBackground();122 Scenario _implementedScenario = Features.implementedScenario();123 Feature _featureWithBackgroundAndScenario = Features.featureWithBackgroundAndScenario(_implementedBackground, _implementedScenario);124 boolean _isPending = _featureWithBackgroundAndScenario.isPending();125 boolean _should_be = Should.<Boolean>should_be(Boolean.valueOf(_isPending), false);126 Assert.assertTrue("\nExpected featureWithBackgroundAndScenario(implementedBackground, implementedScenario).isPending() should be false but"127 + "\n featureWithBackgroundAndScenario(implementedBackground, implementedScenario).isPending() is " + new org.hamcrest.StringDescription().appendValue(Boolean.valueOf(_isPending)).toString()128 + "\n featureWithBackgroundAndScenario(implementedBackground, implementedScenario) is " + new org.hamcrest.StringDescription().appendValue(_featureWithBackgroundAndScenario).toString()129 + "\n implementedBackground is " + new org.hamcrest.StringDescription().appendValue(_implementedBackground).toString()130 + "\n implementedScenario is " + new org.hamcrest.StringDescription().appendValue(_implementedScenario).toString() + "\n", _should_be);131 132 }133}...
Source:SuiteExecutableProviderSpec.java
...104 Suite _suite_1 = this.m.suite("Child 1");105 Suite _suite_2 = this.m.suite("Child 2");106 List<Suite> _list = JnarioCollectionLiterals.<Suite>list(_suite_1, _suite_2);107 Assert.assertTrue("\nExpected subject.getExecutables(suite(\"My Suite\")) => list(suite(\"Child 1\"), suite(\"Child 2\")) but"108 + "\n subject.getExecutables(suite(\"My Suite\")) is " + new org.hamcrest.StringDescription().appendValue(_executables).toString()109 + "\n subject is " + new org.hamcrest.StringDescription().appendValue(this.subject).toString()110 + "\n suite(\"My Suite\") is " + new org.hamcrest.StringDescription().appendValue(_suite).toString()111 + "\n list(suite(\"Child 1\"), suite(\"Child 2\")) is " + new org.hamcrest.StringDescription().appendValue(_list).toString()112 + "\n suite(\"Child 1\") is " + new org.hamcrest.StringDescription().appendValue(_suite_1).toString()113 + "\n suite(\"Child 2\") is " + new org.hamcrest.StringDescription().appendValue(_suite_2).toString() + "\n", Should.<List<? extends Executable>>operator_doubleArrow(_executables, _list));114 115 }116 117 @Test118 @Named("returns resolved specs via link")119 @Order(2)120 public void _returnsResolvedSpecsViaLink() throws Exception {121 StringConcatenation _builder = new StringConcatenation();122 _builder.append("package demo");123 _builder.newLine();124 _builder.append("import demo.*");125 _builder.newLine();126 _builder.append("#My Suite");127 _builder.newLine();128 _builder.newLine();129 _builder.append("- \"My Spec\"");130 _builder.newLine();131 _builder.append("- \"My Feature\"");132 _builder.newLine();133 this.m.parseSuite(_builder);134 Suite _suite = this.m.suite("My Suite");135 List<Executable> _executables = this.subject.getExecutables(_suite);136 Set<Executable> _set = IterableExtensions.<Executable>toSet(_executables);137 ExampleGroup _exampleGroup = this.m.exampleGroup("My Spec");138 Feature _feature = this.m.feature();139 Set<Specification> _set_1 = JnarioCollectionLiterals.<Specification>set(_exampleGroup, _feature);140 Assert.assertTrue("\nExpected subject.getExecutables(suite(\"My Suite\")).toSet => set(exampleGroup(\"My Spec\"), feature()) but"141 + "\n subject.getExecutables(suite(\"My Suite\")).toSet is " + new org.hamcrest.StringDescription().appendValue(_set).toString()142 + "\n subject.getExecutables(suite(\"My Suite\")) is " + new org.hamcrest.StringDescription().appendValue(_executables).toString()143 + "\n subject is " + new org.hamcrest.StringDescription().appendValue(this.subject).toString()144 + "\n suite(\"My Suite\") is " + new org.hamcrest.StringDescription().appendValue(_suite).toString()145 + "\n set(exampleGroup(\"My Spec\"), feature()) is " + new org.hamcrest.StringDescription().appendValue(_set_1).toString()146 + "\n exampleGroup(\"My Spec\") is " + new org.hamcrest.StringDescription().appendValue(_exampleGroup).toString()147 + "\n feature() is " + new org.hamcrest.StringDescription().appendValue(_feature).toString() + "\n", Should.<Set<? extends Executable>>operator_doubleArrow(_set, _set_1));148 149 }150 151 @Test152 @Named("returns resolved specs via regex")153 @Order(3)154 public void _returnsResolvedSpecsViaRegex() throws Exception {155 StringConcatenation _builder = new StringConcatenation();156 _builder.append("package demo");157 _builder.newLine();158 _builder.append("import demo.*");159 _builder.newLine();160 _builder.append("#My Suite");161 _builder.newLine();162 _builder.newLine();163 _builder.append("- \\demo.*\\");164 _builder.newLine();165 _builder.newLine();166 this.m.parseSuite(_builder);167 Suite _suite = this.m.suite("My Suite");168 List<Executable> _executables = this.subject.getExecutables(_suite);169 Set<Executable> _set = IterableExtensions.<Executable>toSet(_executables);170 ExampleGroup _exampleGroup = this.m.exampleGroup("My Spec");171 ExampleGroup _exampleGroup_1 = this.m.exampleGroup("String");172 Feature _feature = this.m.feature();173 Set<Specification> _set_1 = JnarioCollectionLiterals.<Specification>set(_exampleGroup, _exampleGroup_1, _feature);174 Assert.assertTrue("\nExpected subject.getExecutables(suite(\"My Suite\")).toSet => set(exampleGroup(\"My Spec\"), exampleGroup(\"String\"), feature()) but"175 + "\n subject.getExecutables(suite(\"My Suite\")).toSet is " + new org.hamcrest.StringDescription().appendValue(_set).toString()176 + "\n subject.getExecutables(suite(\"My Suite\")) is " + new org.hamcrest.StringDescription().appendValue(_executables).toString()177 + "\n subject is " + new org.hamcrest.StringDescription().appendValue(this.subject).toString()178 + "\n suite(\"My Suite\") is " + new org.hamcrest.StringDescription().appendValue(_suite).toString()179 + "\n set(exampleGroup(\"My Spec\"), exampleGroup(\"String\"), feature()) is " + new org.hamcrest.StringDescription().appendValue(_set_1).toString()180 + "\n exampleGroup(\"My Spec\") is " + new org.hamcrest.StringDescription().appendValue(_exampleGroup).toString()181 + "\n exampleGroup(\"String\") is " + new org.hamcrest.StringDescription().appendValue(_exampleGroup_1).toString()182 + "\n feature() is " + new org.hamcrest.StringDescription().appendValue(_feature).toString() + "\n", Should.<Set<? extends Executable>>operator_doubleArrow(_set, _set_1));183 184 }185}...
Source:ExtensionLibraryCollectionLiteralsSpec.java
...39 ArrayList<String> _newArrayList = CollectionLiterals.<String>newArrayList("green", "red");40 boolean _doubleArrow = Should.<List<String>>operator_doubleArrow(41 Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("green", "red")), _newArrayList);42 Assert.assertTrue("\nExpected #[\"green\", \"red\"] => newArrayList(\"green\", \"red\") but"43 + "\n #[\"green\", \"red\"] is " + new org.hamcrest.StringDescription().appendValue(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("green", "red"))).toString()44 + "\n newArrayList(\"green\", \"red\") is " + new org.hamcrest.StringDescription().appendValue(_newArrayList).toString() + "\n", _doubleArrow);45 46 ArrayList<String> _newArrayList_1 = CollectionLiterals.<String>newArrayList("green");47 ArrayList<String> _newArrayList_2 = CollectionLiterals.<String>newArrayList("red");48 ArrayList<ArrayList<String>> _newArrayList_3 = CollectionLiterals.<ArrayList<String>>newArrayList(_newArrayList_1, _newArrayList_2);49 Assert.assertTrue("\nExpected #[#[\"green\"], #[\"red\"]] => newArrayList(newArrayList(\"green\"), newArrayList(\"red\")) but"50 + "\n #[#[\"green\"], #[\"red\"]] is " + new org.hamcrest.StringDescription().appendValue(Collections.<List<String>>unmodifiableList(CollectionLiterals.<List<String>>newArrayList(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("green")), Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("red"))))).toString()51 + "\n #[\"green\"] is " + new org.hamcrest.StringDescription().appendValue(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("green"))).toString()52 + "\n #[\"red\"] is " + new org.hamcrest.StringDescription().appendValue(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("red"))).toString()53 + "\n newArrayList(newArrayList(\"green\"), newArrayList(\"red\")) is " + new org.hamcrest.StringDescription().appendValue(_newArrayList_3).toString()54 + "\n newArrayList(\"green\") is " + new org.hamcrest.StringDescription().appendValue(_newArrayList_1).toString()55 + "\n newArrayList(\"red\") is " + new org.hamcrest.StringDescription().appendValue(_newArrayList_2).toString() + "\n", Should.<List<? extends List<String>>>operator_doubleArrow(56 Collections.<List<String>>unmodifiableList(CollectionLiterals.<List<String>>newArrayList(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("green")), Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("red")))), _newArrayList_3));57 58 }59 60 @Test61 @Named("Set Literal")62 @Order(2)63 public void _setLiteral() throws Exception {64 HashSet<String> _newHashSet = CollectionLiterals.<String>newHashSet("green", "red");65 boolean _doubleArrow = Should.<Set<String>>operator_doubleArrow(66 Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("green", "red")), _newHashSet);67 Assert.assertTrue("\nExpected #{\"green\", \"red\"} => newHashSet(\"green\", \"red\") but"68 + "\n #{\"green\", \"red\"} is " + new org.hamcrest.StringDescription().appendValue(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("green", "red"))).toString()69 + "\n newHashSet(\"green\", \"red\") is " + new org.hamcrest.StringDescription().appendValue(_newHashSet).toString() + "\n", _doubleArrow);70 71 HashSet<String> _newHashSet_1 = CollectionLiterals.<String>newHashSet("green");72 HashSet<String> _newHashSet_2 = CollectionLiterals.<String>newHashSet("red");73 HashSet<HashSet<String>> _newHashSet_3 = CollectionLiterals.<HashSet<String>>newHashSet(_newHashSet_1, _newHashSet_2);74 Assert.assertTrue("\nExpected #{#{\"green\"}, #{\"red\"}} => newHashSet(newHashSet(\"green\"), newHashSet(\"red\")) but"75 + "\n #{#{\"green\"}, #{\"red\"}} is " + new org.hamcrest.StringDescription().appendValue(Collections.<Set<String>>unmodifiableSet(CollectionLiterals.<Set<String>>newHashSet(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("green")), Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("red"))))).toString()76 + "\n #{\"green\"} is " + new org.hamcrest.StringDescription().appendValue(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("green"))).toString()77 + "\n #{\"red\"} is " + new org.hamcrest.StringDescription().appendValue(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("red"))).toString()78 + "\n newHashSet(newHashSet(\"green\"), newHashSet(\"red\")) is " + new org.hamcrest.StringDescription().appendValue(_newHashSet_3).toString()79 + "\n newHashSet(\"green\") is " + new org.hamcrest.StringDescription().appendValue(_newHashSet_1).toString()80 + "\n newHashSet(\"red\") is " + new org.hamcrest.StringDescription().appendValue(_newHashSet_2).toString() + "\n", Should.<Set<? extends Set<String>>>operator_doubleArrow(81 Collections.<Set<String>>unmodifiableSet(CollectionLiterals.<Set<String>>newHashSet(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("green")), Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("red")))), _newHashSet_3));82 83 }84 85 @Test86 @Named("Map Literal")87 @Order(3)88 public void _mapLiteral() throws Exception {89 Pair<String, String> _mappedTo = Pair.<String, String>of("green", "apple");90 Pair<String, String> _mappedTo_1 = Pair.<String, String>of("yellow", "banana");91 Pair<String, String> _mappedTo_2 = Pair.<String, String>of("red", "tomato");92 Map<String, String> _map = JnarioCollectionLiterals.<String, String>map(_mappedTo, _mappedTo_1, _mappedTo_2);93 Pair<String, String> _mappedTo_3 = Pair.<String, String>of("green", "apple");94 Pair<String, String> _mappedTo_4 = Pair.<String, String>of("yellow", "banana");95 Pair<String, String> _mappedTo_5 = Pair.<String, String>of("red", "tomato");96 HashMap<String, String> _newHashMap = CollectionLiterals.<String, String>newHashMap(_mappedTo_3, _mappedTo_4, _mappedTo_5);97 Assert.assertTrue("\nExpected map(\r\n\t\t \"green\" -> \"apple\",\r\n\t\t \"yellow\" -> \"banana\",\r\n\t\t \"red\" -> \"tomato\"\r\n\t\t ) => newHashMap(\r\n\t\t \"green\" -> \"apple\",\r\n\t\t \"yellow\" -> \"banana\",\r\n\t\t \"red\" -> \"tomato\"\r\n\t\t ) but"98 + "\n map(\r\n\t\t \"green\" -> \"apple\",\r\n\t\t \"yellow\" -> \"banana\",\r\n\t\t \"red\" -> \"tomato\"\r\n\t\t ) is " + new org.hamcrest.StringDescription().appendValue(_map).toString()99 + "\n \"green\" -> \"apple\" is " + new org.hamcrest.StringDescription().appendValue(_mappedTo).toString()100 + "\n \"yellow\" -> \"banana\" is " + new org.hamcrest.StringDescription().appendValue(_mappedTo_1).toString()101 + "\n \"red\" -> \"tomato\" is " + new org.hamcrest.StringDescription().appendValue(_mappedTo_2).toString()102 + "\n newHashMap(\r\n\t\t \"green\" -> \"apple\",\r\n\t\t \"yellow\" -> \"banana\",\r\n\t\t \"red\" -> \"tomato\"\r\n\t\t ) is " + new org.hamcrest.StringDescription().appendValue(_newHashMap).toString() + "\n", Should.<Map<String, String>>operator_doubleArrow(_map, _newHashMap));103 104 }105}...
Source:ArrayMatcherTest.java
...5import static org.hamcrest.Matchers.is;6import static org.hamcrest.Matchers.nullValue;7import org.hamcrest.Description;8import org.hamcrest.Matcher;9import org.hamcrest.StringDescription;10import org.hamcrest.core.IsEqual;11import org.junit.Test;12public class ArrayMatcherTest {13 @Test14 public void testMatchesSafelyWithValues() throws Exception {15 String[] set = array("foo", "bar");16 assertThat(arrayContaining(String.class, "foo", "bar").matchesSafely(set), is(true));17 }18 @Test19 public void testMatchesSafelyWithoutValues() throws Exception {20 String[] set = array();21 assertThat(arrayContaining(String.class).matchesSafely(set), is(true));22 }23 @Test24 public void testMatchesSafelyWithMatcher() throws Exception {25 String[] set = array("foo", "bar");26 assertThat(arrayContaining(String.class, "foo", equalTo("bar")).matchesSafely(set), is(true));27 assertThat(arrayContaining(String.class, equalTo("foo"), "bar").matchesSafely(set), is(true));28 }29 @Test30 public void testMatchesSafelyWithNulls() throws Exception {31 String[] set = array("foo", null);32 assertThat(arrayContaining(String.class, "foo", (String) null).matchesSafely(set), is(true));33 assertThat(arrayContaining(String.class, "foo", nullValue()).matchesSafely(set), is(true));34 }35 @Test36 public void testMatchesSafelyWithValuesFails() throws Exception {37 String[] set = array("foo", "bar");38 assertThat(arrayContaining(String.class, "foo").matchesSafely(set), is(false));39 assertThat(arrayContaining(String.class, "bar").matchesSafely(set), is(false));40 }41 @Test42 public void testMatchesSafelyWithWrongSequenceFails() throws Exception {43 String[] set = array("foo", "bar");44 assertThat(arrayContaining(String.class, "bar", "foo").matchesSafely(set), is(false));45 }46 @Test47 public void testMatchesSafelyWithoutValuesFails() throws Exception {48 String[] set = array("foo");49 assertThat(arrayContaining(String.class).matchesSafely(set), is(false));50 }51 @Test52 public void testMatchesSafelyWithMatcherFails() throws Exception {53 String[] set = array("foo", "bar");54 assertThat(arrayContaining(String.class, equalTo("foobar"), equalTo("foo")).matchesSafely(set), is(false));55 assertThat(arrayContaining(String.class, equalTo("foo"), equalTo("foobar")).matchesSafely(set), is(false));56 }57 @Test58 public void testDescribeTo() throws Exception {59 StringDescription description = new StringDescription();60 arrayContaining(String.class, "foo", "bar").describeTo(description);61 assertThat(description.toString(), equalTo("<[\"foo\", \"bar\"]>"));62 }63 @Test64 public void testDescribeMismatchEntry() throws Exception {65 StringDescription description = new StringDescription();66 arrayContaining(String.class, "foo", "bar").describeMismatch(array("foo", "foobar"), description);67 assertThat(description.toString(), equalTo("mismatching elements <[., was \"foobar\"]>"));68 }69 @Test70 public void testDescribeMismatchUnmatched() throws Exception {71 StringDescription description = new StringDescription();72 arrayContaining(String.class, "foo", "bar").describeMismatch(array("foo", "bar", "foobar"), description);73 assertThat(description.toString(), equalTo("mismatching elements <[.., found 1 elements surplus [was \"foobar\"]]>"));74 }75 @Test76 public void testDescribeMismatchMissing() throws Exception {77 StringDescription description = new StringDescription();78 arrayContaining(String.class, "foo", "bar").describeMismatch(array("foo"), description);79 assertThat(description.toString(), equalTo("mismatching elements <[., missing 1 elements]>"));80 }81 @Test82 public void testDescribeMismatchMissingOnEmpty() throws Exception {83 StringDescription description = new StringDescription();84 arrayContaining(String.class).describeMismatch(array("foo"), description);85 assertThat(description.toString(), equalTo("mismatching elements <[found 1 elements surplus [was \"foo\"]]>"));86 }87 88 @Test89 public void testDescribeMismatchUnmatchedWithCustomMatcher() throws Exception {90 StringDescription description = new StringDescription();91 arrayContaining(String.class, custom("foo")).describeMismatch(array("foobar"), description);92 assertThat(description.toString(), equalTo("mismatching elements <[custom \"foobar\"]>"));93 }94 private Matcher<String> custom(String string) {95 return new IsEqual<String>(string) {96 @Override97 public void describeMismatch(Object item, Description description) {98 description.appendText("custom ").appendValue(item);99 }100 };101 }102 private String[] array(String... elements) {103 return elements;104 }...
Source:UtilityClassMatcherTest.java
...4import static org.hamcrest.MatcherAssert.assertThat;5import static org.hamcrest.Matchers.emptyString;6import static org.hamcrest.Matchers.equalTo;7import java.io.IOException;8import org.hamcrest.StringDescription;9import org.junit.jupiter.api.Test;10public class UtilityClassMatcherTest {11 @Test12 public void testDescribeTo() throws Exception {13 StringDescription description = new StringDescription();14 isUtilityClass().describeTo(description);15 assertThat(description.toString(), equalTo(""16 + "should be declared final"17 + "\nand have a private default constructor doing nothing"18 + "\nand have only static methods"));19 }20 @Test21 public void testMismatchesSafelyNonFinal() throws Exception {22 StringDescription description = new StringDescription();23 24 boolean matches = isUtilityClass().matchesSafely(NotFinal.class, description);25 26 assertThat(matches, is(false));27 assertThat(description.toString(), equalTo("is not declared final"));28 }29 @Test30 public void testMismatchesSafelyNoPrivateConstructor() throws Exception {31 StringDescription description = new StringDescription();32 33 boolean matches = isUtilityClass().matchesSafely(NoPrivateConstructor.class, description);34 35 assertThat(matches, is(false));36 assertThat(description.toString(), equalTo("has not a private default constructor"));37 }38 @Test39 public void testMismatchesSafelyPrivateConstructorThrowingCheckedExceptions() throws Exception {40 StringDescription description = new StringDescription();41 42 boolean matches = isUtilityClass().matchesSafely(PrivateConstructorThrowingCheckedExceptions.class, description);43 44 assertThat(matches, is(false));45 assertThat(description.toString(), equalTo("constructor throws checked exceptions"));46 }47 48 @Test49 public void testMismatchesSafelyNonStaticMethods() throws Exception {50 StringDescription description = new StringDescription();51 52 boolean matches = isUtilityClass().matchesSafely(NonStaticMethods.class, description);53 54 assertThat(matches, is(false));55 assertThat(description.toString(), equalTo("has a non static method \"method\""));56 }57 58 @Test59 public void testMatchesSafelyUtilityClass() throws Exception {60 StringDescription description = new StringDescription();61 62 boolean matches = isUtilityClass().matchesSafely(Utility.class, description);63 64 assertThat(matches, is(true));65 assertThat(description.toString(), emptyString());66 }67 68 @Test69 public void testMatchesSafelyUtilityClassThrowingRuntimeException() throws Exception {70 StringDescription description = new StringDescription();71 72 boolean matches = isUtilityClass().matchesSafely(UtilityThrowingRuntimeException.class, description);73 74 assertThat(matches, is(true));75 assertThat(description.toString(), emptyString());76 }77 78 public static class NotFinal {79 80 }81 public static final class NoPrivateConstructor {82 83 }84 ...
StringDescription
Using AI Code Generation
1import org.hamcrest.StringDescription;2public class HamcrestStringDescription {3 public static void main(String[] args) {4 StringDescription description = new StringDescription();5 description.appendText("This is a text");6 System.out.println(description.toString());7 }8}
StringDescription
Using AI Code Generation
1import org.hamcrest.Description;2import org.hamcrest.StringDescription;3public class StringDescriptionTest {4 public static void main(String[] args) {5 Description description = new StringDescription();6 description.appendText("Hello");7 description.appendText(" World!");8 System.out.println(description.toString());9 }10}
StringDescription
Using AI Code Generation
1import org.hamcrest.StringDescription2import org.hamcrest.MatcherAssert.assertThat3import org.hamcrest.Matchers.*4import org.hamcrest.Matcher5import org.junit.Test6class CustomErrorMessageTest {7 fun testCustomErrorMessage() {8 val matcher = equalTo("Hello")9 val message = StringDescription()10 message.appendText("Expected: ")11 message.appendDescriptionOf(matcher)12 message.appendText(" but: ")13 matcher.describeMismatch(actual, message)14 assertThat(message.toString(), equalTo("Expected: \"Hello\" but: was \"Hello\""))15 }16}17import org.hamcrest.MatcherAssert.assertThat18import org.hamcrest.Matchers.*19import org.junit.Test20class CustomErrorMessageWithHamcrestMatchersTest {21 fun testCustomErrorMessage() {22 val matcher = equalTo("Hello")23 assertThat(actual, matcher)24 }25}
StringDescription
Using AI Code Generation
1import org.hamcrest.StringDescription2import org.hamcrest.Matcher3import org.hamcrest.MatcherAssert4import org.hamcrest.Matchers5import org.hamcrest.Matchers.*6def isEven() {7 return new Matcher<Integer>() {8 boolean matches(Object item) {9 }10 void describeTo(Description description) {11 description.appendText("an even number")12 }13 void describeMismatch(Object item, Description description) {14 description.appendText("was ").appendValue(item)15 }16 }17}18def description = new StringDescription()19isEven().describeMismatch(3, description)20assert description.toString() == "was <3>"21MatcherAssert.assertThat(4, isEven())22MatcherAssert.assertThat(3, not(isEven()))23MatcherAssert.assertThat(4, isEven())24MatcherAssert.assertThat(3, is(not(isEven())))25assertThat(4, isEven())26assertThat(3, is(not(isEven())))27assertThat(4, isEven())28assertThat(3, not(isEven()))29assertThat(4, isEven())30assertThat(3, not(isEven()))31assertThat(4, isEven())32assertThat(3, is(not(isEven())))33assertThat(4, isEven())34assertThat(3, is(not(isEven())))35assertThat(4, isEven())36assertThat(3, is(not(isEven())))37assertThat(4, isEven())38assertThat(3, is(not(isEven())))39assertThat(4, isEven())40assertThat(3, is(not(isEven())))41assertThat(4, isEven())42assertThat(3, not(isEven()))43assertThat(
StringDescription
Using AI Code Generation
1import groovy.transform.CompileStatic2import org.junit.Assert3import org.junit.Test4class StringTest {5 void testString() {6 Assert.assertEquals('hello', s)7 }8}
LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.
Here are the detailed JUnit testing chapters to help you get started:
You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.
Get 100 minutes of automation test minutes FREE!!