blob: 184f7b4d77dcfeb73ce05cfd74121e393305e76c (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc;
import com.google.inject.AbstractModule;
import com.yahoo.jdisc.service.BindingSetNotFoundException;
import com.yahoo.jdisc.test.TestDriver;
import org.junit.Test;
import java.net.URI;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
/**
* @author Simon Thoresen Hult
*/
public class ContainerTestCase {
@Test
public void requireThatNewRequestsReferenceSameSnapshot() throws Exception {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
driver.activateContainer(driver.newContainerBuilder());
Request foo = new Request(driver, URI.create("http://foo"));
Request bar = new Request(foo, URI.create("http://bar"));
assertNotNull(foo.container());
assertSame(foo.container(), bar.container());
foo.release();
bar.release();
driver.close();
}
@Test
public void requireThatInjectionWorks() throws BindingSetNotFoundException {
final Object foo = new Object();
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(new AbstractModule() {
@Override
protected void configure() {
bind(Object.class).toInstance(foo);
}
});
driver.activateContainer(driver.newContainerBuilder());
Request request = new Request(driver, URI.create("http://host/path"));
assertSame(foo, request.container().getInstance(Object.class));
request.release();
driver.close();
}
}
|