@Test
  public void testMatrixParameters() {
    String segment = "segment";
    String segmentMatrixParam = segment + ";param=value";

    String segmentValue = AbstractURLSegment.getActualSegment(segment);
    assertEquals(segment, segmentValue);

    Map<String, String> matrixParams = AbstractURLSegment.getSegmentMatrixParameters(segment);
    assertTrue(matrixParams.size() == 0);

    segmentValue = AbstractURLSegment.getActualSegment(segmentMatrixParam);
    assertEquals(segment, segmentValue);

    matrixParams = AbstractURLSegment.getSegmentMatrixParameters(segmentMatrixParam);

    assertEquals(1, matrixParams.size());

    assertNotNull(matrixParams.get("param"));

    String segmentMatrixParamsQuotes = segment + ";param=value;param1='hello world'";
    matrixParams = AbstractURLSegment.getSegmentMatrixParameters(segmentMatrixParamsQuotes);

    assertEquals(2, matrixParams.size());
    assertEquals("value", matrixParams.get("param"));
    assertEquals("'hello world'", matrixParams.get("param1"));
  }
  /**
   * Method invoked to select the most suited method to serve the current request.
   *
   * @param mappedMethods List of {@link MethodMappingInfo} containing the informations of mapped
   *     methods.
   * @param pageParameters The PageParameters of the current request.
   * @return The "best" method found to serve the request.
   */
  private MethodMappingInfo selectMostSuitedMethod(
      List<MethodMappingInfo> mappedMethods, PageParameters pageParameters) {
    int highestScore = 0;
    MultiMap<Integer, MethodMappingInfo> mappedMethodByScore =
        new MultiMap<Integer, MethodMappingInfo>();

    // no method mapped
    if (mappedMethods == null || mappedMethods.size() == 0) return null;

    /**
     * To select the "best" method, a score is assigned to every mapped method. To calculate the
     * score method calculateScore is executed for every segment.
     */
    for (MethodMappingInfo mappedMethod : mappedMethods) {
      List<AbstractURLSegment> segments = mappedMethod.getSegments();
      int score = 0;

      for (AbstractURLSegment segment : segments) {
        int i = segments.indexOf(segment);
        String currentActualSegment =
            AbstractURLSegment.getActualSegment(pageParameters.get(i).toString());

        int partialScore = segment.calculateScore(currentActualSegment);

        if (partialScore == 0) {
          score = -1;
          break;
        }

        score += partialScore;
      }

      if (score >= highestScore) {
        highestScore = score;
        mappedMethodByScore.addValue(score, mappedMethod);
      }
    }
    // if we have more than one method with the highest score, throw
    // ambiguous exception.
    if (mappedMethodByScore.get(highestScore) != null
        && mappedMethodByScore.get(highestScore).size() > 1)
      throwAmbiguousMethodsException(mappedMethodByScore.get(highestScore));

    return mappedMethodByScore.getFirstValue(highestScore);
  }