|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.client; |
| 21 | + |
| 22 | +import org.elasticsearch.test.ESTestCase; |
| 23 | + |
| 24 | +import java.util.Arrays; |
| 25 | + |
| 26 | +import static org.hamcrest.Matchers.contains; |
| 27 | +import static org.hamcrest.Matchers.hasSize; |
| 28 | + |
| 29 | +public class ValidationExceptionTests extends ESTestCase { |
| 30 | + |
| 31 | + private static final String ERROR = "some-error"; |
| 32 | + private static final String OTHER_ERROR = "some-other-error"; |
| 33 | + |
| 34 | + public void testWithError() { |
| 35 | + ValidationException e = ValidationException.withError(ERROR, OTHER_ERROR); |
| 36 | + assertThat(e.validationErrors(), hasSize(2)); |
| 37 | + assertThat(e.validationErrors(), contains(ERROR, OTHER_ERROR)); |
| 38 | + } |
| 39 | + |
| 40 | + public void testWithErrors() { |
| 41 | + ValidationException e = ValidationException.withErrors(Arrays.asList(ERROR, OTHER_ERROR)); |
| 42 | + assertThat(e.validationErrors(), hasSize(2)); |
| 43 | + assertThat(e.validationErrors(), contains(ERROR, OTHER_ERROR)); |
| 44 | + } |
| 45 | + |
| 46 | + public void testAddValidationError() { |
| 47 | + ValidationException e = new ValidationException(); |
| 48 | + assertThat(e.validationErrors(), hasSize(0)); |
| 49 | + e.addValidationError(ERROR); |
| 50 | + assertThat(e.validationErrors(), hasSize(1)); |
| 51 | + assertThat(e.validationErrors(), contains(ERROR)); |
| 52 | + e.addValidationError(OTHER_ERROR); |
| 53 | + assertThat(e.validationErrors(), hasSize(2)); |
| 54 | + assertThat(e.validationErrors(), contains(ERROR, OTHER_ERROR)); |
| 55 | + } |
| 56 | +} |
0 commit comments