|
| 1 | +/* |
| 2 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 3 | + * |
| 4 | + * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. |
| 5 | + * |
| 6 | + * The contents of this file are subject to the terms of either the GNU |
| 7 | + * General Public License Version 2 only ("GPL") or the Common Development |
| 8 | + * and Distribution License("CDDL") (collectively, the "License"). You |
| 9 | + * may not use this file except in compliance with the License. You can |
| 10 | + * obtain a copy of the License at |
| 11 | + * http://glassfish.java.net/public/CDDL+GPL_1_1.html |
| 12 | + * or packager/legal/LICENSE.txt. See the License for the specific |
| 13 | + * language governing permissions and limitations under the License. |
| 14 | + * |
| 15 | + * When distributing the software, include this License Header Notice in each |
| 16 | + * file and include the License file at packager/legal/LICENSE.txt. |
| 17 | + * |
| 18 | + * GPL Classpath Exception: |
| 19 | + * Oracle designates this particular file as subject to the "Classpath" |
| 20 | + * exception as provided by Oracle in the GPL Version 2 section of the License |
| 21 | + * file that accompanied this code. |
| 22 | + * |
| 23 | + * Modifications: |
| 24 | + * If applicable, add the following below the License Header, with the fields |
| 25 | + * enclosed by brackets [] replaced by your own identifying information: |
| 26 | + * "Portions Copyright [year] [name of copyright owner]" |
| 27 | + * |
| 28 | + * Contributor(s): |
| 29 | + * If you wish your version of this file to be governed by only the CDDL or |
| 30 | + * only the GPL Version 2, indicate your decision by adding "[Contributor] |
| 31 | + * elects to include this software in this distribution under the [CDDL or GPL |
| 32 | + * Version 2] license." If you don't indicate a single choice of license, a |
| 33 | + * recipient has the option to distribute your version of this file under |
| 34 | + * either the CDDL, the GPL Version 2 or to extend the choice of license to |
| 35 | + * its licensees as provided above. However, if you add GPL Version 2 code |
| 36 | + * and therefore, elected the GPL Version 2 license, then the option applies |
| 37 | + * only if the new code is made subject to such option by the copyright |
| 38 | + * holder. |
| 39 | + */ |
| 40 | + |
1 | 41 | package org.glassfish.jersey.internal.inject; |
2 | 42 |
|
3 | 43 | import static org.junit.Assert.assertTrue; |
|
20 | 60 | */ |
21 | 61 | public class InjectionsTest { |
22 | 62 |
|
23 | | - /** |
24 | | - * Verify that services marked with the HK2 Immediate annotation are indeed |
25 | | - * created "immediately" (or at least "soon"). |
26 | | - * |
27 | | - * Because Immediate services are instantiated in a separate thread, we use a |
28 | | - * {@link CountDownLatch} to wait for the service to be created. |
29 | | - * |
30 | | - * After the {@link ServiceLocator} is created, we specifically do not call |
31 | | - * any more methods on it: the locator must instantiate the Immediate service |
32 | | - * without any further prompting to the locator. |
33 | | - * |
34 | | - * @throws InterruptedException |
35 | | - * if awaiting on the latch is interrupted. |
36 | | - */ |
37 | | - @Test |
38 | | - public void testHK2ImmediateAnnotation() throws InterruptedException { |
39 | | - final CountDownLatch latch = new CountDownLatch(1); |
| 63 | + /** |
| 64 | + * Verify that services marked with the HK2 Immediate annotation are indeed |
| 65 | + * created "immediately" (or at least "soon"). |
| 66 | + * |
| 67 | + * Because Immediate services are instantiated in a separate thread, we use |
| 68 | + * a {@link CountDownLatch} to wait for the service to be created. |
| 69 | + * |
| 70 | + * After the {@link ServiceLocator} is created, we specifically do not call |
| 71 | + * any more methods on it: the locator must instantiate the Immediate |
| 72 | + * service without any further prompting to the locator. |
| 73 | + * |
| 74 | + * @throws InterruptedException if awaiting on the latch is interrupted. |
| 75 | + */ |
| 76 | + @Test |
| 77 | + public void testHK2ImmediateAnnotation() throws InterruptedException { |
| 78 | + final CountDownLatch latch = new CountDownLatch(1); |
40 | 79 |
|
41 | | - @SuppressWarnings("unused") // It is unused by design |
42 | | - ServiceLocator sl = Injections.createLocator(new AbstractBinder() { |
43 | | - @Override |
44 | | - protected void configure() { |
45 | | - bind(latch).to(CountDownLatch.class); |
46 | | - bind(ImmediateMe.class).to(ImmediateMe.class).in(Immediate.class); |
47 | | - } |
48 | | - }); |
| 80 | + @SuppressWarnings("unused") // It is unused by design |
| 81 | + ServiceLocator sl = Injections.createLocator(new AbstractBinder() { |
| 82 | + @Override |
| 83 | + protected void configure() { |
| 84 | + bind(latch).to(CountDownLatch.class); |
| 85 | + bind(ImmediateMe.class).to(ImmediateMe.class).in( |
| 86 | + Immediate.class); |
| 87 | + } |
| 88 | + }); |
49 | 89 |
|
50 | | - // 10 seconds is a LONG time. It should be faster than that. However, 10 |
51 | | - // seconds gives us a reasonable upper limit to wait in case the test fails. |
52 | | - assertTrue("Latch should be unlocked within 10 seconds.", |
53 | | - latch.await(10, TimeUnit.SECONDS)); |
54 | | - } |
| 90 | + // 10 seconds is a LONG time. It should be faster than that. However, 10 |
| 91 | + // seconds gives us a reasonable upper limit to wait in case the test |
| 92 | + // fails. |
| 93 | + assertTrue("Latch should be unlocked within 10 seconds.", |
| 94 | + latch.await(10, TimeUnit.SECONDS)); |
| 95 | + } |
55 | 96 |
|
56 | | - /** |
57 | | - * Helper class for testing Immediate services. |
58 | | - * |
59 | | - */ |
60 | | - public static final class ImmediateMe { |
61 | | - @Inject |
62 | | - public ImmediateMe(CountDownLatch latch) { |
63 | | - latch.countDown(); |
| 97 | + /** |
| 98 | + * Helper class for testing Immediate services. |
| 99 | + * |
| 100 | + */ |
| 101 | + public static final class ImmediateMe { |
| 102 | + @Inject |
| 103 | + public ImmediateMe(CountDownLatch latch) { |
| 104 | + latch.countDown(); |
| 105 | + } |
64 | 106 | } |
65 | | - } |
66 | 107 |
|
67 | 108 | } |
0 commit comments