NIHVIVO-1562 Add unit tests for TemplateDirectiveModel and TemplateMethodModel help() methods that return something other than the expected type. Delete HelpDirectiveTest since it just replicated method and help directive tests in DumpDirectiveTest, and was a nuisance to maintain.

This commit is contained in:
ryounes 2011-04-25 14:13:33 +00:00
parent 1b9f4bbdce
commit 1ef114ff45
3 changed files with 78 additions and 297 deletions

View file

@ -286,12 +286,12 @@ public class DumpDirectiveTest {
}
@Test
public void dumpMethodWithBadHelp() {
public void dumpMethodWithStringHelp() {
String varName = "square";
Map<String, Object> dataModel = new HashMap<String, Object>();
TemplateMethodModel methodModel = new MethodWithBadHelp();
TemplateMethodModel methodModel = new MethodWithStringHelp();
dataModel.put(varName, methodModel);
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
@ -304,6 +304,26 @@ public class DumpDirectiveTest {
test(varName, dataModel, expectedDump);
}
@Test
public void dumpMethodWithStringStringMapHelp() {
String varName = "square";
Map<String, Object> dataModel = new HashMap<String, Object>();
TemplateMethodModel methodModel = new MethodWithStringStringMapHelp();
dataModel.put(varName, methodModel);
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
expectedDumpValue.put(Key.CLASS.toString(), methodModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), new HashMap<String, Object>());
Map<String, Object> expectedDump = new HashMap<String, Object>();
expectedDump.put(varName, expectedDumpValue);
test(varName, dataModel, expectedDump);
}
@Test
public void dumpHelplessDirective() {
@ -346,12 +366,12 @@ public class DumpDirectiveTest {
}
@Test
public void dumpDirectiveWithBadHelp() {
public void dumpDirectiveWithStringHelp() {
String varName = "dump";
Map<String, Object> dataModel = new HashMap<String, Object>();
TemplateDirectiveModel directiveModel = new DirectiveWithBadHelp();
TemplateDirectiveModel directiveModel = new DirectiveWithStringHelp();
dataModel.put(varName, directiveModel);
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
@ -364,6 +384,26 @@ public class DumpDirectiveTest {
test(varName, dataModel, expectedDump);
}
@Test
public void dumpDirectiveWithStringStringMapHelp() {
String varName = "dump";
Map<String, Object> dataModel = new HashMap<String, Object>();
TemplateDirectiveModel directiveModel = new DirectiveWithStringStringMapHelp();
dataModel.put(varName, directiveModel);
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
expectedDumpValue.put(Key.CLASS.toString(), directiveModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), new HashMap<String, Object>());
Map<String, Object> expectedDump = new HashMap<String, Object>();
expectedDump.put(varName, expectedDumpValue);
test(varName, dataModel, expectedDump);
}
@Test
public void dumpStringList() {
@ -814,15 +854,27 @@ public class DumpDirectiveTest {
}
}
private class MethodWithBadHelp implements TemplateMethodModel {
private class MethodWithStringHelp implements TemplateMethodModel {
@Override
public Object exec(List arg0) throws TemplateModelException {
return null;
}
public Map<String, Object> help() {
return new HashMap<String, Object>();
public String help(String name) {
return "help";
}
}
private class MethodWithStringStringMapHelp implements TemplateMethodModel {
@Override
public Object exec(List arg0) throws TemplateModelException {
return null;
}
public Map<String, String> help(String name) {
return new HashMap<String, String>();
}
}
@ -848,7 +900,7 @@ public class DumpDirectiveTest {
}
}
private class DirectiveWithBadHelp implements TemplateDirectiveModel {
private class DirectiveWithStringHelp implements TemplateDirectiveModel {
@Override
public void execute(Environment arg0, Map arg1, TemplateModel[] arg2,
@ -860,6 +912,19 @@ public class DumpDirectiveTest {
return "help";
}
}
private class DirectiveWithStringStringMapHelp implements TemplateDirectiveModel {
@Override
public void execute(Environment arg0, Map arg1, TemplateModel[] arg2,
TemplateDirectiveBody arg3) throws TemplateException,
IOException {
}
public Map<String, String> help(String name) {
return new HashMap<String, String>();
}
}
private Map<String, Object> getDirectiveHelp(String name) {
Map<String, Object> map = new HashMap<String, Object>();