zoukankan      html  css  js  c++  java
  • JAVA Assert

    package common;

    import junit.framework.Assert;
    import org.junit.AfterClass;
    import org.junit.BeforeClass;
    import org.junit.Test;
    import org.junit.runners.JUnit4;

    /**
     * Created by IntelliJ IDEA.
     * User: hantongchao
     * Date: 12-8-3
     * Time: 上午9:40
     * To change this template use File | Settings | File Templates.
     */
    public class EnvTest {


        // 在对象初始化之前,马上执行这个方法
        @BeforeClass
        public static void beforeClass() {

        }

        @Test
        public void test() {
            Assert.assertEquals("韩",Env.getInstance().getProperty("han"));
            System.out.println(Env.getInstance().getProperty("han"));  ;//调用

        }

        // 用完之后
        @AfterClass
        public static void afterClass() {

        }

    }

    package common;

    /**
     * Created by IntelliJ IDEA.
     * User: hantongchao
     * Date: 12-8-3
     * Time: 上午9:22
     * To change this template use File | Settings | File Templates.
     */
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;

        /**
         * 读取properties配置文件
         * @author using
         */
        public class Env extends Properties {
            private static  Env instance;

            public static Env getInstance () {
                if(null != instance) {
                    return instance;
                } else {
                    makeInstance();
                    return instance;
                }
            }

            private static synchronized void makeInstance() {
                if(instance == null) {
                    instance = new Env();
                }
            }

            private Env() {
                InputStream is = getClass().getResourceAsStream("/global.properties");
                try {
                    load(is);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            public static void main(String args[]){
              System.out.println(Env.getInstance().getProperty("han"));  ;//调用

            }
        }

  • 相关阅读:
    10 个深恶痛绝的 Java 异常。。
    为什么公司宁愿 25K 重新招人,也不给你加到 20K?原因太现实……
    推荐一款代码神器,代码量至少省一半!
    Spring Cloud Greenwich 正式发布,Hystrix 即将寿终正寝。。
    hdu 3853 LOOPS(概率 dp 期望)
    hdu 5245 Joyful(期望的计算,好题)
    hdu 4336 Card Collector(期望 dp 状态压缩)
    hdu 4405 Aeroplane chess(概率+dp)
    hdu 5036 Explosion(概率期望+bitset)
    hdu 5033 Building (单调栈 或 暴力枚举 )
  • 原文地址:https://www.cnblogs.com/cndavy/p/2621060.html
Copyright © 2011-2022 走看看