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.progress; 6 7 import java.util.*; 8 9 import static org.mockito.internal.util.Primitives.defaultValueForPrimitiveOrWrapper; 10 import static org.mockito.internal.util.Primitives.isPrimitiveOrWrapper; 11 12 @SuppressWarnings("unchecked") 13 public class HandyReturnValues { 14 returnZero()15 public byte returnZero() { 16 return 0; 17 } 18 returnChar()19 public char returnChar() { 20 return 0; 21 } 22 returnNull()23 public <T> T returnNull() { 24 return null; 25 } 26 returnFalse()27 public boolean returnFalse() { 28 return false; 29 } 30 returnString()31 public String returnString() { 32 return ""; 33 } 34 returnFor(Class<T> clazz)35 public <T> T returnFor(Class<T> clazz) { 36 // explicitly return null if type is not a primitive or a wrapper 37 if (isPrimitiveOrWrapper(clazz)) { 38 return defaultValueForPrimitiveOrWrapper(clazz); 39 } 40 return null; 41 } 42 returnMap()43 public Map returnMap() { 44 return new HashMap(); 45 } 46 returnList()47 public List returnList() { 48 return new LinkedList(); 49 } 50 returnSet()51 public Set returnSet() { 52 return new HashSet(); 53 } 54 returnFor(T instance)55 public <T> T returnFor(T instance) { 56 return instance == null ? null : (T) returnFor(instance.getClass()); 57 } 58 }