factorymethodintegrationtests.java

来自「一些很有用的spring的书籍」· Java 代码 · 共 30 行

JAVA
30
字号
package com.apress.springbook.chapter02;

import junit.framework.TestCase;

import org.springframework.core.io.ClassPathResource;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class FactoryMethodIntegrationTests extends TestCase {
   public void testPreInstantiateSingletons() {
      ConfigurableListableBeanFactory beanFactory =
         new XmlBeanFactory(
            new ClassPathResource(
              "com/apress/springbook/chapter02/factory-methods.xml"
            )
         );

      Pattern pattern = (Pattern)beanFactory.getBean("pattern");
      Matcher matcher = pattern.matcher("abc abc abc");
      int matchCount = 0;

      while (matcher.find()) { matchCount++; }

      assertEquals(3, matchCount);
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?