Index: [Article Count Order] [Thread]

Date:  Sat, 16 Sep 2000 22:20:14 +0900
From:  firo@....jp
Subject:  [XP-jp:00893] Re: VXP タスク3 	--Config
To:  extremeprogramming-jp@....jp (extremeprogramming-jp ML)
Message-Id:  <39C377C3.95263051@....jp>
References:  <B5E8632F.3764%khosokawa@....com> <39C3387F.FA986A60@....jp> <39C37014.304BEDA5@....jp>
Posted:  Sat, 16 Sep 2000 22:38:15 +0900
X-Mail-Count: 00893

矢崎です。

firo@....jp wrote:

> (太郎さん)
> コンパイル、テスト、よし通った。
> 後、$-MemberList行がなかった場合も同じような処理
> をすればConfigはおしまいかな?
>

(太郎さん)
ということで、$-MemberListについても同じような対応を
しました。

ConfigTestに
testNoMemberListConfig1、2、3を追加

Configの
String getMemberListFileNameの最初に以下の2行を追加
        if (nameOfMemberListFile == null) throw new IllegalArgumentException();
        if (nameOfMemberListFile.length() == 0) throw new IllegalArgumentException();

コンパイル、テスト実行まで終わったよ。テストも全て通って
います。
花子さん、これでどう?例外の件とか少しまだ検討課題
はあるけれど、Configはおしまいにして先に行く?
それともリファクタリングする?

・・・
/*
 * @(#)ConfigTest.java
 */
package XP.jp.co.esm.wiki.extremedomo;

import junit.framework.*;
import java.io.*;
import java.util.*;

public class ConfigTest extends TestCase {

    public ConfigTest(String name) {
        super(name);
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(ConfigTest.class);
    }

    private void createCorrectConfigFile(String filename) {
        FileOutputStream fo;
        try{
            fo = new FileOutputStream(filename);
        }catch(FileNotFoundException e){
            throw new RuntimeException("unable to open config file");
        }
        PrintWriter pw = new PrintWriter(fo);
        pw.println("X-ML-Name: extremeprogramming-jp");
        pw.println("Y-ML-Name: extremeprogramming-false");
        pw.println("X-Mail-Count: 00796");
        pw.println("Y-Mail-Count: 00888");
        pw.println("$-MemberList: memberlist");
        pw.println("$$-MemberList: memberrrlist");
        pw.println("X-MLServer: fml [fml 2.1_GAMMA#185](distribute only mode)");
        pw.println("Y-MLServer: fml [fml 2.1_GAMMA#185](not distribute only mode)");
        pw.println("X-ML-Info: If you have a question, contact with me");
        pw.println("Y-ML-Info: If you have a question, do not contact with me");
        pw.close();
        try{
            fo.close();
        }catch(IOException e){
            throw new RuntimeException("error on closing  config file");
        }
    }

    public void testCorrectConfig(){
        createCorrectConfigFile("config");

        Config aConfig = new Config("config");

        assertEquals("test1", "extremeprogramming-jp", aConfig.getName());

        Iterator iterator = aConfig.getXInfo();
        assertEquals("test2", "X-ML-Name: extremeprogramming-jp", iterator.next( ));
        assertEquals("test3", "X-Mail-Count: 00796", iterator.next( ));
        assertEquals("test4", "X-MLServer: fml [fml 2.1_GAMMA#185](distribute only mode)",
iterator.next());
        assertEquals("test5", "X-ML-Info: If you have a question, contact with me",
iterator.next());
        assert("test6", ! iterator.hasNext());

        assertEquals("test7", "memberlist", aConfig.getMemberListFileName());
    }

    public void testNoConfigFile(){

        try{
            Config aConfig = new Config("nonconfig");
            fail("Should raise an IllegalArgumentException");
        }catch(IllegalArgumentException e){
            assert(true);
        }

    }

    public void testNoNameConfig1(){
        FileOutputStream fo;
        try{
            fo = new FileOutputStream("badconfig");
        }catch(FileNotFoundException e){
            throw new RuntimeException("unable to open badconfig file");
        }
        PrintWriter pw = new PrintWriter(fo);
        pw.println("Y-ML-Name: extremeprogramming-false");
        pw.println("X-Mail-Count: 00796");
        pw.println("Y-Mail-Count: 00888");
        pw.println("$-MemberList: memberlist");
        pw.println("$$-MemberList: memberrrlist");
        pw.println("X-MLServer: fml [fml 2.1_GAMMA#185](distribute only mode)");
        pw.println("Y-MLServer: fml [fml 2.1_GAMMA#185](not distribute only mode)");
        pw.println("X-ML-Info: If you have a question, contact with me");
        pw.println("Y-ML-Info: If you have a question, do not contact with me");
        pw.close();
        try{
            fo.close();
        }catch(IOException e){
            throw new RuntimeException("error on closing badconfig file");
        }

        try{
            Config aConfig = new Config("badconfig");
            fail("Should raise an IllegalArgumentException1");
        }catch(IllegalArgumentException e){
            assert(true);
        }

    }

    public void testNoNameConfig2(){
        FileOutputStream fo;
        try{
            fo = new FileOutputStream("badconfig");
        }catch(FileNotFoundException e){
            throw new RuntimeException("unable to open badconfig file");
        }
        PrintWriter pw = new PrintWriter(fo);
        pw.println("X-ML-Name:");
        pw.println("X-Mail-Count: 00796");
        pw.println("Y-Mail-Count: 00888");
        pw.println("$-MemberList: memberlist");
        pw.println("$$-MemberList: memberrrlist");
        pw.println("X-MLServer: fml [fml 2.1_GAMMA#185](distribute only mode)");
        pw.println("Y-MLServer: fml [fml 2.1_GAMMA#185](not distribute only mode)");
        pw.println("X-ML-Info: If you have a question, contact with me");
        pw.println("Y-ML-Info: If you have a question, do not contact with me");
        pw.close();
        try{
            fo.close();
        }catch(IOException e){
            throw new RuntimeException("error on closing badconfig file");

        }

        try{
            Config aConfig = new Config("badconfig");
            fail("Should raise an IllegalArgumentException1");
        }catch(IllegalArgumentException e){
            assert(true);
        }

    }

    public void testNoNameConfig3(){
        FileOutputStream fo;
        try{
            fo = new FileOutputStream("badconfig");
        }catch(FileNotFoundException e){
            throw new RuntimeException("unable to open badconfig file");
        }
        PrintWriter pw = new PrintWriter(fo);
        pw.println("X-ML-Name:                              ");
        pw.println("X-Mail-Count: 00796");
        pw.println("Y-Mail-Count: 00888");
        pw.println("$-MemberList: memberlist");
        pw.println("$$-MemberList: memberrrlist");
        pw.println("X-MLServer: fml [fml 2.1_GAMMA#185](distribute only mode)");
        pw.println("Y-MLServer: fml [fml 2.1_GAMMA#185](not distribute only mode)");
        pw.println("X-ML-Info: If you have a question, contact with me");
        pw.println("Y-ML-Info: If you have a question, do not contact with me");
        pw.close();
        try{
            fo.close();
        }catch(IOException e){
            throw new RuntimeException("error on closing badconfig file");

        }

        try{
            Config aConfig = new Config("badconfig");
            fail("Should raise an IllegalArgumentException1");
        }catch(IllegalArgumentException e){
            assert(true);
        }

    }

    public void testNoMemberListConfig1(){
        FileOutputStream fo;
        try{
            fo = new FileOutputStream("badconfig");
        }catch(FileNotFoundException e){
            throw new RuntimeException("unable to open badconfig file");
        }
        PrintWriter pw = new PrintWriter(fo);
        pw.println("X-ML-Name: extremeprogramming-jp");
        pw.println("Y-ML-Name: extremeprogramming-false");
        pw.println("X-Mail-Count: 00796");
        pw.println("Y-Mail-Count: 00888");
        pw.println("$$-MemberList: memberrrlist");
        pw.println("X-MLServer: fml [fml 2.1_GAMMA#185](distribute only mode)");
        pw.println("Y-MLServer: fml [fml 2.1_GAMMA#185](not distribute only mode)");
        pw.println("X-ML-Info: If you have a question, contact with me");
        pw.println("Y-ML-Info: If you have a question, do not contact with me");
        pw.close();
        try{
            fo.close();
        }catch(IOException e){
            throw new RuntimeException("error on closing badconfig file");
        }

        try{
            Config aConfig = new Config("badconfig");
            fail("Should raise an IllegalArgumentException1");
        }catch(IllegalArgumentException e){
            assert(true);
        }

    }

    public void testNoMemberListConfig2(){
        FileOutputStream fo;
        try{
            fo = new FileOutputStream("badconfig");
        }catch(FileNotFoundException e){
            throw new RuntimeException("unable to open badconfig file");
        }
        PrintWriter pw = new PrintWriter(fo);
        pw.println("X-ML-Name: extremeprogramming-jp");
        pw.println("Y-ML-Name: extremeprogramming-false");
        pw.println("X-Mail-Count: 00796");
        pw.println("Y-Mail-Count: 00888");
        pw.println("$-MemberList:");
        pw.println("$$-MemberList: memberrrlist");
        pw.println("X-MLServer: fml [fml 2.1_GAMMA#185](distribute only mode)");
        pw.println("Y-MLServer: fml [fml 2.1_GAMMA#185](not distribute only mode)");
        pw.println("X-ML-Info: If you have a question, contact with me");
        pw.println("Y-ML-Info: If you have a question, do not contact with me");
        pw.close();
        try{
            fo.close();
        }catch(IOException e){
            throw new RuntimeException("error on closing badconfig file");
        }

        try{
            Config aConfig = new Config("badconfig");
            fail("Should raise an IllegalArgumentException1");
        }catch(IllegalArgumentException e){
            assert(true);
        }

    }


    public void testNoMemberListConfig3(){
        FileOutputStream fo;
        try{
            fo = new FileOutputStream("badconfig");
        }catch(FileNotFoundException e){
            throw new RuntimeException("unable to open badconfig file");
        }
        PrintWriter pw = new PrintWriter(fo);
        pw.println("X-ML-Name: extremeprogramming-jp");
        pw.println("Y-ML-Name: extremeprogramming-false");
        pw.println("X-Mail-Count: 00796");
        pw.println("Y-Mail-Count: 00888");
        pw.println("$-MemberList:                       ");
        pw.println("$$-MemberList: memberrrlist");
        pw.println("X-MLServer: fml [fml 2.1_GAMMA#185](distribute only mode)");
        pw.println("Y-MLServer: fml [fml 2.1_GAMMA#185](not distribute only mode)");
        pw.println("X-ML-Info: If you have a question, contact with me");
        pw.println("Y-ML-Info: If you have a question, do not contact with me");
        pw.close();
        try{
            fo.close();
        }catch(IOException e){
            throw new RuntimeException("error on closing badconfig file");
        }

        try{
            Config aConfig = new Config("badconfig");
            fail("Should raise an IllegalArgumentException1");
        }catch(IllegalArgumentException e){
            assert(true);
        }

    }

    protected void setUp() {
    }

    protected void tearDown(){
    }

}


/*
 * @(#)Config.java
 */
package XP.jp.co.esm.wiki.extremedomo;

import java.util.*;
import java.io.*;

public class Config {

    public Config(String nameOfConfigFile) {

        BufferedReader bufIn = null;
        try {
            bufIn = new BufferedReader(new FileReader(nameOfConfigFile));

            String fileLine;

            while (true) {
                fileLine = bufIn.readLine();
                if (fileLine == null)
                    break;

                if (fileLine.startsWith("X-ML-Name:"))
                    name = fileLine.substring("X-ML-Name:".length()).trim();
                if (fileLine.startsWith("$-MemberList:"))
                    nameOfMemberListFile = fileLine.substring("$-MemberList:".length()).trim();
                if (fileLine.startsWith("X-"))
                    xList.add(fileLine.trim());
            }
            getName();
            getMemberListFileName();
        } catch (FileNotFoundException e) {
            // What is exception handling carried out?
            throw new IllegalArgumentException();

        } catch (IOException e) {
            // What is exception handling carried out?
        } finally {
            try {
                if (bufIn != null)
                    bufIn.close();
            } catch (Exception e) {
            }
        }
    }

    public String getName() {
        if (name == null) throw new IllegalArgumentException();
        if (name.length() == 0) throw new IllegalArgumentException();
        return name;
    }

    public Iterator getXInfo() {
        return xList.iterator();
    }

    public String getMemberListFileName(){
        if (nameOfMemberListFile == null) throw new IllegalArgumentException();
        if (nameOfMemberListFile.length() == 0) throw new IllegalArgumentException();
        return nameOfMemberListFile;
    }

    private String name;
    private List xList = new ArrayList();
    private String nameOfMemberListFile;

}


--
矢崎 博英 <firo@....jp>