blob: 870db066dc0783c90ab5c5e9b0ae7fe9c5fc1c76 (
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 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.application;
import org.junit.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.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
/**
* @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
*/
public class BundleInstallationExceptionTestCase {
@Test
public 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
public 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
public 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) {
}
}
}
|