Skip to content

Commit c0af4d0

Browse files
committed
test: tested delegatee resolvation
1 parent d91a117 commit c0af4d0

File tree

5 files changed

+162
-44
lines changed

5 files changed

+162
-44
lines changed

webcal/src/main/java/com/onixbyte/icalendar/datatype/CalendarUserAddress.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public CalendarUserAddress(URI value) {
3030
this.value = value;
3131
}
3232

33+
public CalendarUserAddress(String value) {
34+
var uri = URI.create(value);
35+
if (!"mailto".equalsIgnoreCase(uri.getScheme())) {
36+
throw new IllegalArgumentException("Calendar User Address (CAL-ADDRESS) only accept mailto URI.");
37+
}
38+
this.value = uri;
39+
}
40+
3341
@Override
3442
public String toString() {
3543
return value.toString();

webcal/src/main/java/com/onixbyte/icalendar/property/parameter/Delegatee.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.net.URI;
2323
import java.util.ArrayList;
2424
import java.util.List;
25+
import java.util.function.Supplier;
2526

2627
/**
2728
* Delegate
@@ -38,15 +39,39 @@ private Delegatee(List<CalendarUserAddress> value) {
3839
this.value = value;
3940
}
4041

42+
public static Builder builder() {
43+
return new Builder();
44+
}
45+
4146
public static class Builder {
4247
private List<CalendarUserAddress> value;
4348

4449
private Builder() {
4550
this.value = new ArrayList<>();
4651
}
4752

48-
public Builder addDelegatee(URI delegateeUri) {
49-
value.add(new CalendarUserAddress(delegateeUri));
53+
public Builder addDelegatee(CalendarUserAddress delegatee) {
54+
value.add(delegatee);
55+
return this;
56+
}
57+
58+
public Builder addDelegatee(URI delegatee) {
59+
value.add(new CalendarUserAddress(delegatee));
60+
return this;
61+
}
62+
63+
public Builder addDelegatee(String delegatee) {
64+
value.add(new CalendarUserAddress(delegatee));
65+
return this;
66+
}
67+
68+
public Builder addDelegatees(List<CalendarUserAddress> delegatees) {
69+
value.addAll(delegatees);
70+
return this;
71+
}
72+
73+
public Builder addDelegatees(Supplier<List<CalendarUserAddress>> delegatees) {
74+
value.addAll(delegatees.get());
5075
return this;
5176
}
5277

webcal/src/main/resources/logback.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
~ Copyright (C) 2023 CodeCraftersCN.
3+
~ Copyright (C) 2024-2024 OnixByte.
44
~
55
~ Licensed under the Apache License, Version 2.0 (the "License");
66
~ you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616
~ limitations under the License.
1717
-->
1818
<configuration>
19-
<property name="COLOURFUL_OUTPUT" value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
19+
<property name="COLOURFUL_OUTPUT" value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%15.15t]) %cyan(%-39.39logger{39}) %black(:) %msg%n"/>
2020
<property name="STANDARD_OUTPUT" value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
2121

2222
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
}

webcal/src/test/java/com/onixbyte/icalendar/test/TestCalendar.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)