@Test public void testFailsGracefullyToDefaultWhenLastMapperThrows() { when(subMapper2.getProfileFname(person, request)).thenThrow(RuntimeException.class); String fname = mapper.getProfileFname(person, request); assertEquals("profile", fname); }
@Override public String getProfileFname(IPerson person, HttpServletRequest request) { for (IProfileMapper mapper : subMappers) { try { final String fname = mapper.getProfileFname(person, request); if (fname != null) { logger.debug("Profile mapper {} found profile fname={}", mapper, fname); return fname; } } catch (final Exception mapperThrownException) { logger.error( "Profile mapper " + mapper + " threw on attempt to map profile.", mapperThrownException); } } logger.trace( "None of the chained profile mappers [{}] mapped to a profile, " + "so returning default profile [{}].", subMappers, defaultProfileName); return defaultProfileName; }
ChainingProfileMapperImpl implements IProfileMapper { @Override public String getProfileFname(IPerson person, HttpServletRequest request) { for (IProfileMapper mapper : subMappers) { try { final String fname = mapper.getProfileFname(person, request); if (fname != null) { logger.debug("Profile mapper {} found profile fname={}", mapper, fname); return fname; } } catch (final Exception mapperThrownException) { logger.error( "Profile mapper " + mapper + " threw on attempt to map profile.", mapperThrownException); } } logger.trace( "None of the chained profile mappers [{}] mapped to a profile, " + "so returning default profile [{}].", subMappers, defaultProfileName); return defaultProfileName; } }
ChainingProfileMapperImpl implements IProfileMapper { @Override public String getProfileFname(IPerson person, HttpServletRequest request) { for (IProfileMapper mapper : subMappers) { try { final String fname = mapper.getProfileFname(person, request); if (fname != null) { logger.debug("Profile mapper {} found profile fname={}", mapper, fname); return fname; } } catch (final Exception mapperThrownException) { logger.error( "Profile mapper " + mapper + " threw on attempt to map profile.", mapperThrownException); } } logger.trace( "None of the chained profile mappers [{}] mapped to a profile, " + "so returning default profile [{}].", subMappers, defaultProfileName); return defaultProfileName; }  }
ChainingProfileMapperImpl implements IProfileMapper { @Override public String getProfileFname(IPerson person, HttpServletRequest request) { for (IProfileMapper mapper : subMappers) { try { final String fname = mapper.getProfileFname(person, request); if (fname != null) { logger.debug("Profile mapper {} found profile fname={}", mapper, fname); return fname; } } catch (final Exception mapperThrownException) { logger.error( "Profile mapper " + mapper + " threw on attempt to map profile.", mapperThrownException); } } logger.trace( "None of the chained profile mappers [{}] mapped to a profile, " + "so returning default profile [{}].", subMappers, defaultProfileName); return defaultProfileName; }  void setDefaultProfileName(String defaultProfileName); void setSubMappers(List<IProfileMapper> subMappers); @Override String getProfileFname(IPerson person, HttpServletRequest request); @Override String toString(); }
ChainingProfileMapperImpl implements IProfileMapper { @Override public String getProfileFname(IPerson person, HttpServletRequest request) { for (IProfileMapper mapper : subMappers) { try { final String fname = mapper.getProfileFname(person, request); if (fname != null) { logger.debug("Profile mapper {} found profile fname={}", mapper, fname); return fname; } } catch (final Exception mapperThrownException) { logger.error( "Profile mapper " + mapper + " threw on attempt to map profile.", mapperThrownException); } } logger.trace( "None of the chained profile mappers [{}] mapped to a profile, " + "so returning default profile [{}].", subMappers, defaultProfileName); return defaultProfileName; }  void setDefaultProfileName(String defaultProfileName); void setSubMappers(List<IProfileMapper> subMappers); @Override String getProfileFname(IPerson person, HttpServletRequest request); @Override String toString();  }