|
| 1 | +/* |
| 2 | + * Copyright (C) 2024-2024 OnixByte. |
| 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 | + * |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.onixbyte.icalendar.test; |
| 19 | + |
| 20 | +import com.onixbyte.icalendar.datatype.CalendarUserAddress; |
| 21 | +import com.onixbyte.icalendar.property.parameter.Delegatee; |
| 22 | +import lombok.extern.slf4j.Slf4j; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | +import java.net.URI; |
| 26 | +import java.util.List; |
| 27 | +import java.util.stream.Stream; |
| 28 | + |
| 29 | +@Slf4j |
| 30 | +public class DelegateeTest { |
| 31 | + |
| 32 | + @Test |
| 33 | + void testAddStringDelegatee() { |
| 34 | + var delegatee = Delegatee.builder() |
| 35 | + .addDelegatee("mailto:user01@example.onixbyte.com") |
| 36 | + .build() |
| 37 | + .resolve(); |
| 38 | + log.info("#testAddStringDelegatee {}", delegatee); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + void testAddUriDelegatee() { |
| 43 | + var delegatee = Delegatee.builder() |
| 44 | + .addDelegatee(URI.create("mailto:user01@example.onixbyte.com")) |
| 45 | + .build() |
| 46 | + .resolve(); |
| 47 | + log.info("#testAddUriDelegatee {}", delegatee); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void testAddCauDelegateeWithStringConstructor() { |
| 52 | + var delegatee = Delegatee.builder() |
| 53 | + .addDelegatee(new CalendarUserAddress("mailto:user01@example.onixbyte.com")) |
| 54 | + .build() |
| 55 | + .resolve(); |
| 56 | + log.info("#testAddCauDelegateeWithStringConstructor {}", delegatee); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void testAddCauDelegateeWithUriConstructor() { |
| 61 | + var delegatee = Delegatee.builder() |
| 62 | + .addDelegatee(new CalendarUserAddress(URI.create("mailto:user01@example.onixbyte.com"))) |
| 63 | + .build() |
| 64 | + .resolve(); |
| 65 | + log.info("#testAddCauDelegateeWithUriConstructor {}", delegatee); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + void testAddDelegateeSeparately() { |
| 70 | + var delegatee = Delegatee.builder() |
| 71 | + .addDelegatee(new CalendarUserAddress(URI.create("mailto:user01@example.onixbyte.com"))) |
| 72 | + .addDelegatee(URI.create("mailto:user02@example.onixbyte.com")) |
| 73 | + .addDelegatee("mailto:user03@example.onixbyte.com") |
| 74 | + .build() |
| 75 | + .resolve(); |
| 76 | + log.info("#testAddDelegateeSeparately {}", delegatee); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + void testAddDelegateeSeparatelyWithIncorrectUri() { |
| 81 | + try { |
| 82 | + var delegatee = Delegatee.builder() |
| 83 | + .addDelegatee(new CalendarUserAddress(URI.create("mailto:user01@example.onixbyte.com"))) |
| 84 | + .addDelegatee(URI.create("mailto:user02@example.onixbyte.com")) |
| 85 | + .addDelegatee("https://example.onixbyte.com") |
| 86 | + .build() |
| 87 | + .resolve(); |
| 88 | + log.info("#testAddDelegateeSeparatelyWithIncorrectUri {}", delegatee); |
| 89 | + } catch (IllegalArgumentException iae) { |
| 90 | + log.error("#testAddDelegateeSeparatelyWithIncorrectUri {}", iae.getMessage()); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + void testAddDelegateesWithCau() { |
| 96 | + try { |
| 97 | + var delegatee = Delegatee.builder() |
| 98 | + .addDelegatees(List.of( |
| 99 | + new CalendarUserAddress("mailto:user01@example.onixbyte.com"), |
| 100 | + new CalendarUserAddress("mailto:user02@example.onixbyte.com") |
| 101 | + )) |
| 102 | + .build() |
| 103 | + .resolve(); |
| 104 | + log.info("#testAddDelegateesWithCau {}", delegatee); |
| 105 | + } catch (IllegalArgumentException iae) { |
| 106 | + log.error("#testAddDelegateesWithCau {}", iae.getMessage()); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + void testAddDelegateesWithSupplier() { |
| 112 | + try { |
| 113 | + var delegatee = Delegatee.builder() |
| 114 | + .addDelegatees(() -> Stream.of("mailto:user01@example.onixbyte.com", "mailto:user02@example.onixbyte.com") |
| 115 | + .map(CalendarUserAddress::new) |
| 116 | + .toList()) |
| 117 | + .build() |
| 118 | + .resolve(); |
| 119 | + log.info("#testAddDelegateesWithSupplier {}", delegatee); |
| 120 | + } catch (IllegalArgumentException iae) { |
| 121 | + log.error("#testAddDelegateesWithSupplier {}", iae.getMessage()); |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | +} |
0 commit comments