1 package com.simpligility.maven.plugins.android; 2 3 import com.google.common.collect.Lists; 4 import com.simpligility.maven.plugins.android.InstrumentationArgumentParser; 5 6 import org.junit.Rule; 7 import org.junit.Test; 8 import org.junit.rules.ExpectedException; 9 10 import java.util.List; 11 import java.util.Map; 12 13 import static org.hamcrest.CoreMatchers.is; 14 import static org.junit.Assert.assertThat; 15 import static org.junit.Assert.assertTrue; 16 17 public class InstrumentationArgumentParserTest 18 { 19 @Rule 20 public final ExpectedException expectedException = ExpectedException.none(); 21 22 @Test 23 public void should_return_an_empty_map_for_null_list() 24 { 25 assertTrue( InstrumentationArgumentParser.parse( null ).isEmpty() ); 26 } 27 28 @Test 29 public void two_flat_args_should_be_parsed_into_two_key_value_pairs() 30 { 31 final List<String> flatArgs = Lists.newArrayList( "key1 value1", "key2 value2" ); 32 final Map<String,String> parsedArgs = InstrumentationArgumentParser.parse( flatArgs ); 33 34 assertThat( parsedArgs.get( "key1" ), is( "value1" ) ); 35 assertThat( parsedArgs.get( "key2" ), is( "value2" ) ); 36 } 37 38 @Test 39 public void should_parse_values_with_space_character() 40 { 41 final List<String> flatArgs = Lists.newArrayList( "key1 'value with spaces'" ); 42 final Map<String,String> parsedArgs = InstrumentationArgumentParser.parse( flatArgs ); 43 44 assertThat( parsedArgs.get( "key1" ), is( "'value with spaces'" ) ); 45 } 46 47 @Test 48 public void missing_value_should_throw_IllegalArgumentException() 49 { 50 expectedException.expect( IllegalArgumentException.class ); 51 expectedException.expectMessage( is( "Could not separate \"key1\" by a whitespace into two parts" ) ); 52 53 final List<String> flatArgs = Lists.newArrayList( "key1" ); 54 InstrumentationArgumentParser.parse( flatArgs ); 55 } 56 57 @Test 58 public void empty_pair_should_throw_IllegalArgumentException() 59 { 60 expectedException.expect( IllegalArgumentException.class ); 61 expectedException.expectMessage( is( "Could not separate \"\" by a whitespace into two parts" ) ); 62 63 final List<String> flatArgs = Lists.newArrayList( "" ); 64 InstrumentationArgumentParser.parse( flatArgs ); 65 } 66 }