|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2017 Intuit |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + *******************************************************************************/ |
| 16 | +package com.intuit.oauth2.config; |
| 17 | + |
| 18 | +import com.intuit.oauth2.exception.InvalidRequestException; |
| 19 | +import org.testng.annotations.DataProvider; |
| 20 | +import org.testng.annotations.Test; |
| 21 | + |
| 22 | +import java.util.HashSet; |
| 23 | +import java.util.Iterator; |
| 24 | +import java.util.Set; |
| 25 | + |
| 26 | +import static org.testng.Assert.*; |
| 27 | + |
| 28 | +/** |
| 29 | + * Config class to hold the proxy properties |
| 30 | + * |
| 31 | + * @author dderose |
| 32 | + */ |
| 33 | +public class ScopeTest { |
| 34 | + |
| 35 | + @Test(expectedExceptions = IllegalArgumentException.class) |
| 36 | + public void testfromValueforIllegalArgument() |
| 37 | + { |
| 38 | + String badenum ="I am bad value"; |
| 39 | + Scope.fromValue(badenum); |
| 40 | + fail(badenum + " is not present in the Scope enum"); |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | + @DataProvider(parallel = true, name = "validScopeValuesdp") |
| 45 | + public Iterator<Object[]> validScopeValuesdp() { |
| 46 | + |
| 47 | + Set<Object[]> dataToBeReturned = new HashSet<>(); |
| 48 | + |
| 49 | + for (Scope scope : Scope.values()) { |
| 50 | + dataToBeReturned.add(new Object[]{scope.name(), scope.value()}); |
| 51 | + } |
| 52 | + return dataToBeReturned.iterator(); |
| 53 | + } |
| 54 | + |
| 55 | + |
| 56 | + @Test(dataProvider = "validScopeValuesdp") |
| 57 | + public void testfromValueforInvalidArgument(String name, String value) |
| 58 | + { |
| 59 | + try{ |
| 60 | + Scope returnedScope = Scope.fromValue(value); |
| 61 | + assertNotNull(returnedScope); |
| 62 | + assertTrue(returnedScope.name().equals(name)); |
| 63 | + } catch (Exception e) |
| 64 | + { |
| 65 | + fail(value + "is a valid Scope enumvalue."); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | +} |
0 commit comments