### Question:
ConfigLoader { protected static Pattern constructPattern(MappingEndpoint endpoint) { String path = endpoint.getExternalEndpoint(); if (path.contains("{") && endpoint.getVarName() != null && endpoint.getVarExpression() != null) { String [] varNames = endpoint.getVarName().split(" "); String [] varExpressions = endpoint.getVarExpression().split(" "); String end = ""; for (int i = 0; i < varNames.length; i++) { if ((i == varNames.length - 1) && endpoint.getExternalEndpoint().endsWith("}")) { end = (varExpressions[i].endsWith(END)) ? "": END; } String varExpr = String.format(VAR_EXPRESSION_FORMAT, varExpressions[i], end); String varName = String.format(VAR_NAME_FORMAT, varNames[i]); path = path.replace(varName, varExpr); }; return Pattern.compile(path); } else { return Pattern.compile(path + END); } } private  ConfigLoader(); static void loadCustomHandlers(); static Class<?> loadCustomClass(String className); static List<MappingConfig> getConfig(); static void updateMapping(String name, MappingConfig value); static void removeMapping(String name); static void reloadConfigs(); static Map<String, MappingConfig> getLoadedMappings(); static Map<Integer, String> getLoadedGlobalErrors(); static void updateError(Integer status, String message); static void removeError(Integer status);  }### Answer:
@Test public void when_mapping_with_RE_construct_Pattern() throws Exception { MappingEndpoint endpoint = new MappingEndpoint(); endpoint.setExternalEndpoint("/v0.1/payments/{paymentId}"); endpoint.setInternalEndpoint("/v0.1/payments/{paymentId}"); endpoint.setVarExpression("\\d*"); endpoint.setVarName("paymentId"); Pattern p = ConfigLoader.constructPattern(endpoint); assertEquals(p.toString(), "/v0.1/payments/(\\d*)$"); }
@Test public void when_mapping_with_RE_varName_not_at_the_end_construct_Pattern_without_$() throws Exception { MappingEndpoint endpoint = new MappingEndpoint(); endpoint.setExternalEndpoint("/v0.1/payments/{paymentId}/info"); endpoint.setInternalEndpoint("/v0.1/payments/{paymentId}/info"); endpoint.setVarExpression("\\d*"); endpoint.setVarName("paymentId"); Pattern p = ConfigLoader.constructPattern(endpoint); assertEquals(p.toString(), "/v0.1/payments/(\\d*)/info"); }