Home | History | Annotate | Download | only in matchers
      1 /*
      2  * Copyright (c) 2007 Mockito contributors
      3  * This program is made available under the terms of the MIT License.
      4  */
      5 package org.mockito.internal.matchers;
      6 
      7 import java.util.LinkedList;
      8 import java.util.List;
      9 
     10 import org.hamcrest.Description;
     11 import org.hamcrest.Matcher;
     12 import org.hamcrest.SelfDescribing;
     13 import org.hamcrest.StringDescription;
     14 import org.mockito.internal.reporting.PrintSettings;
     15 
     16 @SuppressWarnings("unchecked")
     17 public class MatchersPrinter {
     18 
     19     public String getArgumentsLine(List<Matcher> matchers, PrintSettings printSettings) {
     20         Description result = new StringDescription();
     21         result.appendList("(", ", ", ");", applyPrintSettings(matchers, printSettings));
     22         return result.toString();
     23     }
     24 
     25     public String getArgumentsBlock(List<Matcher> matchers, PrintSettings printSettings) {
     26         Description result = new StringDescription();
     27         result.appendList("(\n    ", ",\n    ", "\n);", applyPrintSettings(matchers, printSettings));
     28         return result.toString();
     29     }
     30 
     31     private List<SelfDescribing> applyPrintSettings(List<Matcher> matchers, PrintSettings printSettings) {
     32         List<SelfDescribing> withPrintSettings = new LinkedList<SelfDescribing>();
     33         int i = 0;
     34         for (final Matcher matcher : matchers) {
     35             if (matcher instanceof ContainsExtraTypeInformation && printSettings.extraTypeInfoFor(i)) {
     36                 withPrintSettings.add(((ContainsExtraTypeInformation) matcher).withExtraTypeInfo());
     37             } else {
     38                 withPrintSettings.add(matcher);
     39             }
     40             i++;
     41         }
     42         return withPrintSettings;
     43     }
     44 }