01: package org.drools.decisiontable.model;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import junit.framework.TestCase;
20:
21: /**
22: * @author <a href="mailto:michael.neale@gmail.com"> Michael Neale</a>
23: *
24: */
25: public class SnippetBuilderTest extends TestCase {
26:
27: public void testBuildSnippet() {
28: final String snippet = "something.param.getAnother().equals($param);";
29: final SnippetBuilder snip = new SnippetBuilder(snippet);
30: final String cellValue = "$42";
31: final String result = snip.build(cellValue);
32: assertNotNull(result);
33:
34: assertEquals("something.param.getAnother().equals($42);",
35: result);
36: }
37:
38: public void testBuildSnippetNoPlaceHolder() {
39: final String snippet = "something.getAnother().equals(blah);";
40: final SnippetBuilder snip = new SnippetBuilder(snippet);
41: final String cellValue = "this is ignored...";
42: final String result = snip.build(cellValue);
43:
44: assertEquals(snippet, result);
45: }
46:
47: public void testSingleParamMultipleTimes() {
48: final String snippet = "something.param.getAnother($param).equals($param);";
49: final SnippetBuilder snip = new SnippetBuilder(snippet);
50: final String cellValue = "42";
51: final String result = snip.build(cellValue);
52: assertNotNull(result);
53:
54: assertEquals("something.param.getAnother(42).equals(42);",
55: result);
56:
57: }
58:
59: public void testMultiPlaceHolder() {
60: final String snippet = "something.getAnother($1,$2).equals($2, '$2');";
61: final SnippetBuilder snip = new SnippetBuilder(snippet);
62: final String result = snip.build("x, y");
63: assertEquals("something.getAnother(x,y).equals(y, 'y');",
64: result);
65:
66: }
67:
68: public void testMultiPlaceHolderSingle() {
69: final String snippet = "something.getAnother($1).equals($1);";
70: final SnippetBuilder snip = new SnippetBuilder(snippet);
71: final String result = snip.build("x");
72: assertEquals("something.getAnother(x).equals(x);", result);
73:
74: }
75:
76: public void testStartWithParam() {
77: final String snippet = "$1 goo $2";
78: final SnippetBuilder snip = new SnippetBuilder(snippet);
79: final String result = snip.build("x, y");
80: assertEquals("x goo y", result);
81:
82: }
83:
84: }
|