Skip to content

Commit

Permalink
WELD-2413 Weld SE test
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Aug 9, 2017
1 parent 5d86eea commit 1fba586
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
@@ -0,0 +1,38 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2017, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.weld.environment.se.test.container.provider;

import java.util.concurrent.atomic.AtomicBoolean;

import javax.annotation.PreDestroy;
import javax.enterprise.context.Dependent;

@Dependent
public class Baz {

static final AtomicBoolean DISPOSED = new AtomicBoolean(false);

boolean ping() {
return true;
}

@PreDestroy
void dispose() {
DISPOSED.set(true);
}

}
Expand Up @@ -17,6 +17,7 @@
package org.jboss.weld.environment.se.test.container.provider;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -84,6 +85,16 @@ public void testExtension() {
}
}

@Test
public void testDependentInstanceDestroyedDuringShutdown() {
Baz.DISPOSED.set(false);
try (WeldContainer weldContainer = new Weld().disableDiscovery().beanClasses(Baz.class).initialize()) {
assertTrue(CDI.current().select(Baz.class).get().ping());
assertFalse(Baz.DISPOSED.get());
}
assertTrue(Baz.DISPOSED.get());
}

private void assertCdi(CDI<Object> cdi, String id) {
assertTrue(cdi instanceof WeldContainer);
assertEquals(id, ((WeldContainer) cdi).getId());
Expand Down

0 comments on commit 1fba586

Please sign in to comment.