|
| 1 | +/* |
| 2 | + * Copyright 2015 Google Inc. All Rights Reserved. |
| 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 | + |
| 17 | +package com.google.gcloud; |
| 18 | + |
| 19 | +import static org.junit.Assert.assertFalse; |
| 20 | +import static org.junit.Assert.assertSame; |
| 21 | +import static org.junit.Assert.assertTrue; |
| 22 | +import static org.junit.Assert.fail; |
| 23 | + |
| 24 | +import org.junit.Before; |
| 25 | +import org.junit.Test; |
| 26 | + |
| 27 | +public class BatchResultTest { |
| 28 | + |
| 29 | + private BatchResult<Boolean, BaseServiceException> RESULT; |
| 30 | + |
| 31 | + @Before |
| 32 | + public void setUp() { |
| 33 | + RESULT = new BatchResult<Boolean, BaseServiceException>() {}; |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void testSuccess() { |
| 38 | + assertFalse(RESULT.submitted()); |
| 39 | + try { |
| 40 | + RESULT.get(); |
| 41 | + fail("This was not submitted yet."); |
| 42 | + } catch (IllegalStateException ex) { |
| 43 | + // expected |
| 44 | + } |
| 45 | + RESULT.success(true); |
| 46 | + assertTrue(RESULT.get()); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testError() { |
| 51 | + assertFalse(RESULT.submitted()); |
| 52 | + try { |
| 53 | + RESULT.get(); |
| 54 | + fail("This was not submitted yet."); |
| 55 | + } catch (IllegalStateException ex) { |
| 56 | + // expected |
| 57 | + } |
| 58 | + BaseServiceException ex = new BaseServiceException(0, "message", "reason", false); |
| 59 | + RESULT.error(ex); |
| 60 | + try { |
| 61 | + RESULT.get(); |
| 62 | + fail("This is a failed operation and should have thrown a DnsException."); |
| 63 | + } catch (BaseServiceException real) { |
| 64 | + assertSame(ex, real); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + // todo(mderka) test notify when implemented |
| 69 | + |
| 70 | +} |
0 commit comments