Blogs

  • Browse Blogs
  • My Blog
  • My Updates

Tags Help

  • View as cloud  | list

Similar Entries

photo

Re: Quick Tip: Runni...

Blog:  The Notes Tra...
Tony Austin
Updated 
No RatingsRatings 0     No CommentsComments 0
photo

Quick Tip: Running S...

Blog:  Beyond The Ye...
Peter Presnell
Updated 
No RatingsRatings 0     CommentsComments 2
photo

XPages - The Good, T...

Blog:  Beyond The Ye...
Peter Presnell
Updated 
No RatingsRatings 0     CommentsComments 1
photo

Running multiple ver...

Blog:  Yellow is the...
Tim Tripcony
Updated 
No RatingsRatings 0     No CommentsComments 0

Jan Schulz

Blog Authors:  Jan Schulz  

Previous |  Main  | Next

assertThat(me, is_(aBlogPost()).and_(is_(interesting())) :-)

Jan Schulz  |     |  Tags:  testing validation hamcrest  |  Comments (1)
A few days ago I found Hamcrest on the web. It's a framework, which lets you write validation rules in almost plain english:
Dim value as Variant
value = "Hallo"
Call assertThat(value, is_( not_( equalTo("Hallo") ) ).and_(is_(ofType("String")))

Resulting in output like this:

Assertion failure: expected: is not equal to Hallo and is of type STRING; got: (STRING) Hallo

(bold is from the Matcher (second argument to assertThat), rest from the Error, which the assertThat method throws)

The Implementation is quite easy: you have a IMatcher abstract Class with several concrete matcher implementation and a static method, which returns a object of that matcher. The IsMatcher (just to have proper english sentences :-) and the static method looks like this:

Public Function is_(matcher As IMatcher) As IMatcher
Set is_ = New IsMatcher(matcher)
End Function

Class IsMatcher As IMatcher
Private fMatcher As IMatcher

Sub new(matcher As IMatcher)
Set fMatcher = matcher
End Sub

Public Function matchesSafely( value As Variant) As Boolean
matchesSafely = fMatcher.matches(value)
End Function

Public Function describeMeTo(description As Description)
description.appendText("is")
Call fMatcher.describeTo(description)
End Function
End Class

The testThat (just returns a boolean, assertThat uses that to throw the error) is just:

Public Function testThat(value As Variant, matcher As IMatcher) As Boolean
testThat = matcher.matches(value)
End Functio

IMatcher.matches(variant) is a wrapper to get the IMatcher.and_(IMatcher) and IMatcher.Or_(IMatcher) methods working. In the end it returns the logical result of all included Matchers.

The IMatcher.decribeMeTo(Description) is again the internal method (describeTo(...) is the wrapper to get AND and OR working) used to get the plain english description from the matcher composite (the bold Text above).

Dim oDescription As New Description
Call matcher.describeTo(oDescription)
print oDescription.toString()


Implemented Matchers up to now: is, not, equalTo, ofType, instanceOf, like. Feel free to add some matchers or leave a comment for other ideas :-)

Here is the script lib as it is up to now (BleedYellow seems to not allow any Notes/Domino related content: no *.lss, no *.nsf):

Edited, as I can upload now: LS-Hamcrest.lss

Comments

1 Chris Whisonant      Permalink Jan, you may now upload .lss, .nsf, AND .ntf. I completely overlooked that this is a "Yellow" site and the those pesky developers may want to upload "Yellow" files! ;)

I also added .zip and .rar.


Previous |  Main  | Next
Skip to main content link. Accesskey S
IBM Lotus Connections Help Tools About

Tags

A tag is a keyword that is used to categorize an entry. To view the entries with a particular tag, click a tag name or enter a tag in the box.
The tag cloud indicates the frequency of tag use. Popular tags appear darkest. The slider control adjusts how many tags are displayed in the tag cloud.