Skip to content

Commit 2188295

Browse files
committed
Remove sugar generation example.
1 parent f386d56 commit 2188295

File tree

1 file changed

+0
-54
lines changed

1 file changed

+0
-54
lines changed

docs/tutorial.md

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -172,57 +172,3 @@ public class NumberTest extends TestCase {
172172
```
173173

174174
Even though the `notANumber` method creates a new matcher each time it is called, you should not assume this is the only usage pattern for your matcher. Therefore you should make sure your matcher is stateless, so a single instance can be reused between matches.
175-
176-
### Sugar generation (TBD)
177-
If you produce more than a few custom matchers it becomes annoying to have to import them all individually. It would be nice to be able to group them together in a single class, so they can be imported using a single static import much like the Hamcrest library matchers. Hamcrest helps out here by providing a way to do this by using a generator.
178-
179-
First, create an XML configuration file listing all the Matcher classes that should be searched for factory methods annotated with the org.hamcrest.Factory annotation. For example:
180-
181-
```
182-
TBD
183-
```
184-
185-
Second, run the org.hamcrest.generator.config.XmlConfigurator command-line tool that comes with Hamcrest. This tool takes the XML configuration file and generates a single Java class that includes all the factory methods specified by the XML file. Running it with no arguments will display a usage message. Here's the output for the example.
186-
187-
```java
188-
package org.hamcrest.examples.tutorial;
189-
190-
public class Matchers {
191-
192-
public static org.hamcrest.Matcher is(T param1) {
193-
return org.hamcrest.core.Is.is(param1);
194-
}
195-
196-
public static org.hamcrest.Matcher is(java.lang.Class param1) {
197-
return org.hamcrest.core.Is.is(param1);
198-
}
199-
200-
public static org.hamcrest.Matcher is(org.hamcrest.Matcher param1) {
201-
return org.hamcrest.core.Is.is(param1);
202-
}
203-
204-
public static org.hamcrest.Matcher notANumber() {
205-
return org.hamcrest.examples.tutorial.IsNotANumber.notANumber();
206-
}
207-
208-
}
209-
```
210-
211-
Finally, we can update our test to use the new Matchers class.
212-
213-
```java
214-
import static org.hamcrest.MatcherAssert.assertThat;
215-
216-
import static org.hamcrest.examples.tutorial.Matchers.*;
217-
218-
import junit.framework.TestCase;
219-
220-
public class CustomSugarNumberTest extends TestCase {
221-
222-
public void testSquareRootOfMinusOneIsNotANumber() {
223-
assertThat(Math.sqrt(-1), is(notANumber()));
224-
}
225-
}
226-
```
227-
228-
Notice we are now using the Hamcrest library is matcher imported from our own custom Matchers class.

0 commit comments

Comments
 (0)