|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2009, 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.e4.core.tests.services.internal.annotations; |
| 12 |
|
| 13 |
import javax.inject.Inject; |
| 14 |
import javax.inject.Named; |
| 15 |
|
| 16 |
import junit.framework.TestCase; |
| 17 |
|
| 18 |
import org.eclipse.e4.core.services.IDisposable; |
| 19 |
import org.eclipse.e4.core.services.annotations.PreDestroy; |
| 20 |
import org.eclipse.e4.core.services.context.EclipseContextFactory; |
| 21 |
import org.eclipse.e4.core.services.context.IEclipseContext; |
| 22 |
import org.eclipse.e4.core.services.context.spi.ContextInjectionFactory; |
| 23 |
|
| 24 |
public class InjectionOrderTest extends TestCase { |
| 25 |
|
| 26 |
public static class InjectTargetMethod { |
| 27 |
Object o; |
| 28 |
|
| 29 |
@Inject |
| 30 |
void set(@Named("inject") Object o) { |
| 31 |
this.o = o; |
| 32 |
} |
| 33 |
|
| 34 |
@PreDestroy |
| 35 |
void pd() { |
| 36 |
assertNotNull(o); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
public static class InjectTargetField { |
| 41 |
@Inject @Named("inject") |
| 42 |
Object o; |
| 43 |
|
| 44 |
@PreDestroy |
| 45 |
void pd() { |
| 46 |
assertNotNull(o); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
public void testDisposeMethod() throws Exception { |
| 51 |
IEclipseContext appContext = EclipseContextFactory.create(); |
| 52 |
appContext.set("inject", "a"); |
| 53 |
|
| 54 |
ContextInjectionFactory.make(InjectTargetMethod.class, appContext); |
| 55 |
appContext.set("inject", "b"); |
| 56 |
|
| 57 |
((IDisposable) appContext).dispose(); |
| 58 |
} |
| 59 |
|
| 60 |
public void testDisposeField() throws Exception { |
| 61 |
IEclipseContext appContext = EclipseContextFactory.create(); |
| 62 |
appContext.set("inject", "a"); |
| 63 |
|
| 64 |
ContextInjectionFactory.make(InjectTargetField.class, appContext); |
| 65 |
appContext.set("inject", "b"); |
| 66 |
|
| 67 |
((IDisposable) appContext).dispose(); |
| 68 |
} |
| 69 |
} |