1 /* 2 * Copyright (c) 2011-2025 Yegor Bugayenko 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 1) Redistributions of source code must retain the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer. 2) Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following 12 * disclaimer in the documentation and/or other materials provided 13 * with the distribution. 3) Neither the name of the Qulice.com nor 14 * the names of its contributors may be used to endorse or promote 15 * products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 20 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 21 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 package com.qulice.maven; 32 33 import com.qulice.spi.ResourceValidator; 34 import com.qulice.spi.Validator; 35 import java.util.HashSet; 36 import java.util.Set; 37 import org.mockito.Mockito; 38 39 /** 40 * Mocker of ValidatorsProvider. 41 * @since 0.4 42 */ 43 final class ValidatorsProviderMocker { 44 45 /** 46 * List of external validators. 47 */ 48 private final Set<Validator> external = new HashSet<>(); 49 50 /** 51 * List of external resource validators. 52 */ 53 private final transient Set<ResourceValidator> rexternal = new HashSet<>(); 54 55 /** 56 * List of internal validators. 57 */ 58 private final Set<MavenValidator> internal = new HashSet<>(); 59 60 /** 61 * With this external validator. 62 * @param validator The validator 63 * @return This object 64 */ 65 public ValidatorsProviderMocker withExternal(final Validator validator) { 66 this.external.add(validator); 67 return this; 68 } 69 70 /** 71 * With this external resource validator. 72 * @param validator The validator 73 * @return This object 74 */ 75 public ValidatorsProviderMocker withExternalResource( 76 final ResourceValidator validator) { 77 this.rexternal.add(validator); 78 return this; 79 } 80 81 /** 82 * With this external validator. 83 * @param validator The validator 84 * @return This object 85 */ 86 public ValidatorsProviderMocker withInternal( 87 final MavenValidator validator) { 88 this.internal.add(validator); 89 return this; 90 } 91 92 /** 93 * Mock it. 94 * @return The provider 95 */ 96 public ValidatorsProvider mock() { 97 final ValidatorsProvider provider = 98 Mockito.mock(ValidatorsProvider.class); 99 Mockito.doReturn(this.internal).when(provider).internal(); 100 Mockito.doReturn(this.external).when(provider).external(); 101 Mockito.doReturn(this.rexternal).when(provider).externalResource(); 102 return provider; 103 } 104 105 }