/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* or http://forgerock.org/license/CDDLv1.0.html.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2013 ForgeRock AS.
*/
package org.forgerock.opendj.config;
import static org.mockito.Mockito.*;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.Collection;
import java.util.SortedSet;
import java.util.TreeSet;
import org.mockito.invocation.InvocationOnMock;
import org.opends.server.admin.AbsoluteInheritedDefaultBehaviorProvider;
import org.opends.server.admin.AliasDefaultBehaviorProvider;
import org.opends.server.admin.Configuration;
import org.opends.server.admin.DefaultBehaviorProvider;
import org.opends.server.admin.DefaultBehaviorProviderVisitor;
import org.opends.server.admin.DefinedDefaultBehaviorProvider;
import org.opends.server.admin.ManagedObjectDefinition;
import org.opends.server.admin.PropertyDefinition;
import org.opends.server.admin.PropertyDefinitionsOptions;
import org.opends.server.admin.PropertyOption;
import org.opends.server.admin.RelativeInheritedDefaultBehaviorProvider;
import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
/**
* Provides Mockito mocks for Configuration objects with default values
* corresponding to those defined in xml configuration files.
*
* These mocks can be used like any other mocks, e.g, you can define stubs using
* {@code when} method or verify calls using {@code verify} method.
*
*/
public final class ConfigurationMock {
private static final ConfigAnswer CONFIG_ANSWER = new ConfigAnswer();
/**
* Returns a mock for the provided configuration class.
*
* If a setting has a default value, the mock automatically returns the
* default value when the getter is called on the setting.
*
* It is possible to override this default behavior with the usual methods
* calls with Mockito (e.g, {@code when} method).
*
* @param
* The type of configuration.
* @param configClass
* The configuration class.
* @return a mock
*/
public static T mockCfg(Class configClass) {
return mock(configClass, CONFIG_ANSWER);
}
/**
* A stubbed answer for Configuration objects, allowing to return default
* value for settings when available.
*/
private static class ConfigAnswer implements org.mockito.stubbing.Answer