### Question:
MappingResourceObjectProvider implements ResourceObjectProvider, ResourceObjectProviderAdapter { @Override public ResourceObject get(String name, ResourceResolutionContext context) throws MissingResourceObjectException { for (Mapping mapping : mappings) { if (mapping.pattern.matcher(name).matches()) { return mapping.provider.get(name, context); } } throw new MissingResourceObjectException(name, context.toString()); }  @Override String toString(); void setMappings(Map<String,ResourceObjectProvider> mappings); @Override ResourceObject get(String name, ResourceResolutionContext context); @Override List<ResourceObjectProvider> unwrap();  }### Answer:
@Test public void testMappingSelectedInCorrectSequence() throws Exception { FileResourceObjectRepository files = filesIn(folder.getRoot()); MappingResourceObjectProvider provider = patternMatching() .when(".*\\.txt$", files) .otherwise(inHeap()); ResourceObject object = given(anObject("test","-en_US",".txt")); files.put(object.name(), in(Locale.US), object::asStream); ResourceObject file = provider.get(object.name(), in(Locale.US)); assertEquals(object.name(), file.name()); assertTrue(file.actualName().endsWith(object.actualName())); assertEquals(object.size(), file.size()); }
@Test(expected=MissingResourceObjectException.class) public void testMappingSelectedInCorrectSequence2() throws Exception { FileResourceObjectRepository files = filesIn(folder.getRoot()); MappingResourceObjectProvider provider = patternMatching() .when(".+", inHeap()) .otherwise(".*\\.txt$", files); ResourceObject object = given(anObject("test","-en_US",".txt")); files.put(object.name(), in(Locale.US), object::asStream); provider.get(object.name(), in(Locale.US)); }