001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.cli2; 018 019import org.apache.commons.cli2.option.ArgumentTest; 020import org.apache.commons.cli2.option.PropertyOption; 021 022/** 023 * @author Rob Oxspring 024 */ 025public abstract class WriteableCommandLineTestCase extends CommandLineTestCase { 026 027 private WriteableCommandLine writeable; 028 029 protected abstract WriteableCommandLine createWriteableCommandLine(); 030 031 /* (non-Javadoc) 032 * @see org.apache.commons.cli2.CommandLineTest#createCommandLine() 033 */ 034 protected final CommandLine createCommandLine() { 035 final WriteableCommandLine cl = createWriteableCommandLine(); 036 cl.addOption(present); 037 cl.addProperty(new PropertyOption(), "present","present property"); 038 cl.addSwitch(bool,true); 039 cl.addValue(present,"present value"); 040 cl.addOption(multiple); 041 cl.addValue(multiple,"value 1"); 042 cl.addValue(multiple,"value 2"); 043 cl.addValue(multiple,"value 3"); 044 return cl; 045 } 046 047 /* 048 * @see CommandLineTest#setUp() 049 */ 050 public void setUp() throws Exception { 051 super.setUp(); 052 writeable = createWriteableCommandLine(); 053 } 054 public final void testAddOption() { 055 assertFalse(writeable.hasOption(present)); 056 writeable.addOption(present); 057 assertTrue(writeable.hasOption(present)); 058 } 059 public final void testAddValue() { 060 assertFalse(writeable.hasOption(present)); 061 assertTrue(writeable.getValues(present).isEmpty()); 062 writeable.addValue(present,"value"); 063 assertContentsEqual(list("value"),writeable.getValues(present)); 064 065 // most options shouldn't appear due to adding values 066 assertFalse(writeable.hasOption(present)); 067 068 final Argument arg = ArgumentTest.buildHostArgument(); 069 070 assertFalse(writeable.hasOption(arg)); 071 assertTrue(writeable.getValues(arg).isEmpty()); 072 writeable.addValue(arg,"value"); 073 assertContentsEqual(list("value"),writeable.getValues(arg)); 074 075 // Arguments should force the option present 076 assertTrue(writeable.hasOption(arg)); 077 } 078 public final void testAddSwitch() { 079 assertFalse(writeable.hasOption(present)); 080 assertNull(writeable.getSwitch(present)); 081 writeable.addSwitch(present,true); 082 assertEquals(Boolean.TRUE,writeable.getSwitch(present)); 083 assertTrue(writeable.hasOption(present)); 084 } 085 public final void testAddProperty() { 086 assertNull(writeable.getProperty(new PropertyOption(), "present")); 087 writeable.addProperty(new PropertyOption(), "present","present value"); 088 assertEquals("present value",writeable.getProperty(new PropertyOption(), "present")); 089 } 090 public final void testLooksLikeOption() { 091 //TODO Implement looksLikeOption(). 092 } 093}