### Question:
RegexKeyManifestFilter implements ManifestFilter { public Map<String, String> match( final Map<String, String> entries ) { final Map<String, String> matching = new HashMap<String, String>(); if( entries != null && !entries.isEmpty() ) { for( Map.Entry<String, String> entry : entries.entrySet() ) { if( m_pattern.matcher( entry.getKey() ).matches() ) { matching.put( entry.getKey(), entry.getValue() ); } } } return matching; } RegexKeyManifestFilter( final String regexp ); Map<String, String> match( final Map<String, String> entries );  }### Answer:
@Test public void match01() { final Map<String, String> entries = new HashMap<String, String>(); entries.put( "k1", "v1" ); entries.put( "k2", "v2" ); final Map<String, String> expected = new HashMap<String, String>(); expected.put( "k1", "v1" ); final Map<String, String> filtered = new RegexKeyManifestFilter( "k1" ).match( entries ); assertThat( "Manifest entries", filtered, is( notNullValue() ) ); assertThat( "Filtered manifest entries", filtered, is( equalTo( expected ) ) ); }
@Test public void match02() { final Map<String, String> entries = new HashMap<String, String>(); entries.put( "k1", "v1" ); entries.put( "k2", "v2" ); entries.put( "k3", "v3" ); final Map<String, String> expected = new HashMap<String, String>(); expected.put( "k1", "v1" ); expected.put( "k3", "v3" ); final Map<String, String> filtered = new RegexKeyManifestFilter( "k[13]" ).match( entries ); assertThat( "Manifest entries", filtered, is( notNullValue() ) ); assertThat( "Filtered manifest entries", filtered, is( equalTo( expected ) ) ); }
@Test public void matchAgainstNullMap() { final Map<String, String> filtered = new RegexKeyManifestFilter( "k1" ).match( null ); assertThat( "Manifest entries", filtered, is( notNullValue() ) ); assertThat( "Filtered manifest entries", filtered, is( equalTo( Collections.<String, String>emptyMap() ) ) ); }
@Test public void matchAgainstEmptyMap() { final Map<String, String> filtered = new RegexKeyManifestFilter( "k1" ).match( Collections.<String, String>emptyMap() ); assertThat( "Manifest entries", filtered, is( notNullValue() ) ); assertThat( "Filtered manifest entries", filtered, is( equalTo( Collections.<String, String>emptyMap() ) ) ); }