首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Spring 3.0 诠释

2012-08-21 
Spring 3.0 注释.package org.springframework.samples.config.basic.accountimport static org.hamcrest

Spring 3.0 注释.

package org.springframework.samples.config.basic.account;import static org.hamcrest.CoreMatchers.equalTo;import static org.junit.Assert.assertThat;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.annotation.AnnotationConfigApplicationContext;import org.springframework.samples.config.basic.account.domain.Account;import org.springframework.samples.config.basic.account.repository.AccountRepository;import org.springframework.samples.config.basic.account.service.TransferService;public class TransferServiceTest {@Testpublic void transfer100Dollars() {// create the spring container using the AppConfig @Configuration classApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);// retrieve the beans we'll use during testingAccountRepository accountRepository = ctx.getBean(AccountRepository.class);TransferService transferService = ctx.getBean(TransferService.class);// create accounts to test againstaccountRepository.add(new Account("A123", 1000.00));accountRepository.add(new Account("C456", 0.00));// check account balances before transferassertThat(accountRepository.findById("A123").getBalance(), equalTo(1000.00));assertThat(accountRepository.findById("C456").getBalance(), equalTo(0.00));// perform transfertransferService.transfer(100.00, "A123", "C456");// check account balances after transferassertThat(accountRepository.findById("A123").getBalance(), equalTo(900.00));assertThat(accountRepository.findById("C456").getBalance(), equalTo(100.00));}}

热点排行