AllHelper implements Helper<Object> { @Override public CharSequence apply( final Object computedContext, final Options options ) throws IOException { Object context = options.context.model(); String componentPath = null; if( computedContext instanceof String ) componentPath = (String) computedContext; if( Utils.isEmptyOrWhitespaces( componentPath )) componentPath = InstanceFilter.JOKER; CharSequence result = StringUtils.EMPTY; if (context instanceof ApplicationContextBean) { result = safeApply(((ApplicationContextBean) context).getInstances(), options, componentPath ); } else if (context instanceof InstanceContextBean) { result = safeApply( descendantInstances((InstanceContextBean) context), options, componentPath ); } else { this.logger.warning( "An unexpected context was received: " + (context == null ? null : context.getClass())); } return result; }  @Override CharSequence apply( final Object computedContext, final Options options ); static final String NAME; }
@Test public void testUnsupportedContext_unknownType() throws Exception { Context ctx = Context.newContext( new Object()); Handlebars handlebars = Mockito.mock( Handlebars.class ); Template tpl = Mockito.mock( Template.class ); Options opts = new Options( handlebars, "helper", TagType.SECTION, ctx, tpl, tpl, new Object[ 0 ], new HashMap<String,Object>( 0 )); AllHelper helper = new AllHelper(); Assert.assertEquals( "", helper.apply( null, opts )); }
@Test public void testUnsupportedContext_nullContext() throws Exception { Context ctx = Context.newContext( null ); Handlebars handlebars = Mockito.mock( Handlebars.class ); Template tpl = Mockito.mock( Template.class ); Options opts = new Options( handlebars, "helper", TagType.SECTION, ctx, tpl, tpl, new Object[ 0 ], new HashMap<String,Object>( 0 )); AllHelper helper = new AllHelper(); Assert.assertEquals( "", helper.apply( null, opts )); }