1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.mail.internal; |
21 |
|
|
22 |
|
import javax.mail.Address; |
23 |
|
import javax.mail.internet.InternetAddress; |
24 |
|
|
25 |
|
import org.junit.Rule; |
26 |
|
import org.junit.Test; |
27 |
|
import org.xwiki.properties.converter.ConversionException; |
28 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
29 |
|
|
30 |
|
import static org.junit.Assert.*; |
31 |
|
|
32 |
|
|
33 |
|
@link |
34 |
|
|
35 |
|
@version |
36 |
|
@since |
37 |
|
|
|
|
| 94.1% |
Uncovered Elements: 1 (17) |
Complexity: 5 |
Complexity Density: 0.38 |
|
38 |
|
public class AddressesConverterTest |
39 |
|
{ |
40 |
|
@Rule |
41 |
|
public MockitoComponentMockingRule<AddressesConverter> mocker = |
42 |
|
new MockitoComponentMockingRule<>(AddressesConverter.class); |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
44 |
1 |
@Test... |
45 |
|
public void convert() throws Exception |
46 |
|
{ |
47 |
1 |
InternetAddress[] addresses = new InternetAddress[2]; |
48 |
1 |
addresses[0] = new InternetAddress("John Doe(comment) <john1@doe.com>"); |
49 |
1 |
addresses[1] = new InternetAddress("john2@doe.com"); |
50 |
1 |
assertArrayEquals(addresses, (InternetAddress[]) this.mocker.getComponentUnderTest().convert(Address[].class, |
51 |
|
"John Doe(comment) <john1@doe.com>,john2@doe.com")); |
52 |
|
} |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
54 |
1 |
@Test... |
55 |
|
public void convertWhenNull() throws Exception |
56 |
|
{ |
57 |
1 |
assertNull(this.mocker.getComponentUnderTest().convert(Address.class, null)); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
60 |
1 |
@Test... |
61 |
|
public void convertWhenTypeIsAlreadyAnAddressArray() throws Exception |
62 |
|
{ |
63 |
1 |
InternetAddress[] addresses = new InternetAddress[2]; |
64 |
1 |
addresses[0] = new InternetAddress("John Doe(comment) <john1@doe.com>"); |
65 |
1 |
addresses[1] = new InternetAddress("john2@doe.com"); |
66 |
1 |
assertArrayEquals(addresses, |
67 |
|
(InternetAddress[]) this.mocker.getComponentUnderTest().convert(Address.class, addresses)); |
68 |
|
} |
69 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
70 |
1 |
@Test... |
71 |
|
public void convertWhenInvalid() throws Exception |
72 |
|
{ |
73 |
1 |
try { |
74 |
1 |
this.mocker.getComponentUnderTest().convert(Address[].class, "invalid("); |
75 |
0 |
fail("Should have thrown an exception here"); |
76 |
|
} catch (ConversionException expected) { |
77 |
1 |
assertEquals("Failed to convert [invalid(] to an array of [javax.mail.Address]", expected.getMessage()); |
78 |
|
} |
79 |
|
} |
80 |
|
} |