blob: d16f13814c180b3676da79df3daf22bb046b7266 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.application;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.osgi.framework.Bundle;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Simon Thoresen Hult
*/
public class BundleInstallationExceptionTestCase {
@Test
void requireThatAccessorsWork() {
Throwable t = new Throwable("foo");
Collection<Bundle> bundles = new LinkedList<>();
bundles.add(Mockito.mock(Bundle.class));
BundleInstallationException e = new BundleInstallationException(bundles, t);
assertSame(t, e.getCause());
assertEquals(t.getMessage(), e.getCause().getMessage());
assertEquals(bundles, e.installedBundles());
}
@Test
void requireThatBundlesCollectionIsDefensivelyCopied() {
Collection<Bundle> bundles = new LinkedList<>();
bundles.add(Mockito.mock(Bundle.class));
BundleInstallationException e = new BundleInstallationException(bundles, new Throwable());
bundles.add(Mockito.mock(Bundle.class));
assertEquals(1, e.installedBundles().size());
}
@Test
void requireThatBundlesCollectionIsUnmodifiable() {
BundleInstallationException e = new BundleInstallationException(Arrays.asList(Mockito.mock(Bundle.class)),
new Throwable());
try {
e.installedBundles().add(Mockito.mock(Bundle.class));
fail();
} catch (UnsupportedOperationException f) {
}
}
}
|