com.github.tuxychandru.spring.mustache.MustacheViewResolverTest.java Source code

Java tutorial

Introduction

Here is the source code for com.github.tuxychandru.spring.mustache.MustacheViewResolverTest.java

Source

/*
 * Copyright (C) 2013 Chandra Sekar S
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.tuxychandru.spring.mustache;

import java.util.Locale;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.web.servlet.View;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.mockito.AdditionalAnswers.*;

public class MustacheViewResolverTest {

    private final ApplicationContext mockContext;
    private final AutowireCapableBeanFactory mockBeanFactory;

    public MustacheViewResolverTest() {
        mockContext = mock(ApplicationContext.class);
        mockBeanFactory = mock(AutowireCapableBeanFactory.class);
        when(mockContext.getAutowireCapableBeanFactory()).thenReturn(mockBeanFactory);
        when(mockBeanFactory.initializeBean(any(View.class), anyString())).thenAnswer(returnsFirstArg());
    }

    @Test
    public void testResolution() throws Exception {
        MustacheViewResolver resolver = new MustacheViewResolver();
        resolver.setApplicationContext(mockContext);
        resolver.setPrefix("views/");
        resolver.setSuffix(".html");

        MustacheView view = (MustacheView) resolver.resolveViewName("abc", Locale.CANADA);
        assertEquals("views/abc.html", view.getUrl());
    }
}