Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package es.unileon.ulebank.service; import es.unileon.ulebank.domain.Bank; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; import org.springframework.validation.BeanPropertyBindingResult; import org.springframework.validation.BindingResult; import org.springframework.web.servlet.ModelAndView; /** * * @author dorian */ public class SearchClientControllerTest { SearchClientController instance; Bank bank; @Before public void setUp() { instance = new SearchClientController(); } /** * Test of onSubmit method, of class SearchClientController. */ @Test public void testOnSubmit() { System.out.println("onSubmit"); DniClient dniCorrect = new DniClient(); DniClient dniIncorrect = new DniClient(); dniIncorrect.setDni("incorrect"); dniCorrect.setDni("96443956B"); BindingResult bindingResult = new BeanPropertyBindingResult(dniCorrect, "dniCorrect"); System.out.println(bindingResult.getErrorCount()); //problems with bindingResult, can not make working this test //tried to move source code to SearchManager without sucess-> at least, I can test //that piece of source code in another test file // ModelAndView result = instance.onSubmit(dniCorrect, bindingResult); // assertEquals("showClient", result.getViewName()); // result = instance.onSubmit(dniIncorrect, bindingResult); // assertEquals("searchClient", result.getViewName()); } /** * Test of formBackingObject method, of class SearchClientController. */ @Test public void testFormBackingObject() throws Exception { System.out.println("formBackingObject"); DniClient expResult = new DniClient(); expResult.setDni(""); DniClient result = instance.formBackingObject(null); assertEquals(expResult.getDni(), result.getDni()); } /** * Test of getBank method, of class SearchClientController. */ @Test public void testGetBank() { System.out.println("getBank"); Bank expResult = bank; Bank result = instance.getBank(); assertEquals(expResult, result); } /** * Test of setBank method, of class SearchClientController. */ @Test public void testSetBank() { System.out.println("setBank"); Bank anotherBank = null; Bank result = instance.getBank(); assertEquals(this.bank, result); instance.setBank(anotherBank); result = instance.getBank(); assertEquals(anotherBank, result); } }