Skip to content

Commit

Permalink
Convert tests to JUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Aug 17, 2010
1 parent 50e9127 commit 267909f
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 77 deletions.
11 changes: 2 additions & 9 deletions environments/se/core/pom.xml
Expand Up @@ -34,16 +34,9 @@

<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<classifier>jdk15</classifier>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Expand Up @@ -16,15 +16,18 @@
*/
package org.jboss.weld.environment.se.test;

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

import org.jboss.weld.environment.se.ShutdownManager;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.jboss.weld.environment.se.test.decorators.AbstractDoor;
import org.jboss.weld.environment.se.test.decorators.CarDoor;
import org.jboss.weld.environment.se.test.decorators.CarDoorAlarm;
import org.jboss.weld.environment.se.test.decorators.HouseDoor;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.junit.Test;

/**
*
Expand All @@ -42,36 +45,36 @@ public void testDecorators()
WeldContainer weld = new Weld().initialize();

CarDoor carDoor = weld.instance().select(CarDoor.class).get();
Assert.assertNotNull(carDoor);
assertNotNull(carDoor);

// the car door is alarmed
CarDoorAlarm.alarmActivated = false;
Assert.assertFalse(CarDoorAlarm.alarmActivated);
assertFalse(CarDoorAlarm.alarmActivated);
testDoor(carDoor);
Assert.assertTrue(CarDoorAlarm.alarmActivated);
assertTrue(CarDoorAlarm.alarmActivated);

HouseDoor houseDoor = weld.instance().select(HouseDoor.class).get();
Assert.assertNotNull(carDoor);
assertNotNull(carDoor);

// the house door is not alarmed
CarDoorAlarm.alarmActivated = false;
Assert.assertFalse(CarDoorAlarm.alarmActivated);
assertFalse(CarDoorAlarm.alarmActivated);
testDoor(houseDoor);
Assert.assertFalse(CarDoorAlarm.alarmActivated);
assertFalse(CarDoorAlarm.alarmActivated);

shutdownManager(weld);
}

private void testDoor(AbstractDoor door)
{
Assert.assertTrue(door.open());
Assert.assertTrue(door.isOpen());
Assert.assertFalse(door.close());
Assert.assertFalse(door.isOpen());
Assert.assertTrue(door.lock());
Assert.assertTrue(door.isLocked());
Assert.assertFalse(door.open());
Assert.assertFalse(door.isOpen());
assertTrue(door.open());
assertTrue(door.isOpen());
assertFalse(door.close());
assertFalse(door.isOpen());
assertTrue(door.lock());
assertTrue(door.isLocked());
assertFalse(door.open());
assertFalse(door.isOpen());
}

private void shutdownManager(WeldContainer weld)
Expand Down
Expand Up @@ -16,12 +16,14 @@
*/
package org.jboss.weld.environment.se.test;

import static org.junit.Assert.assertFalse;

import org.jboss.weld.environment.se.ShutdownManager;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.jboss.weld.environment.se.events.ContainerInitialized;
import org.jboss.weld.environment.se.test.events.Foo;
import org.testng.annotations.Test;
import org.junit.Test;

/**
*
Expand All @@ -30,13 +32,14 @@
public class EventsTest
{

@Test(description="forum post check")
// forum post check
@Test
public void testEventQualifiersCorrect()
{
Foo.reset();
WeldContainer weld = new Weld().initialize();
weld.event().select(ContainerInitialized.class).fire(new ContainerInitialized());
assert !Foo.isObservedEventTest();
assertFalse(Foo.isObservedEventTest());
shutdownManager(weld);
}

Expand Down
Expand Up @@ -15,17 +15,17 @@
* limitations under the License.
*/
package org.jboss.weld.environment.se.test;

import javax.enterprise.inject.spi.BeanManager;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.jboss.weld.environment.se.ShutdownManager;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.jboss.weld.environment.se.test.beans.InterceptorTestBean;
import org.jboss.weld.environment.se.test.interceptors.AggregatingInterceptor;
import org.jboss.weld.environment.se.test.interceptors.RecordingInterceptor;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.junit.Test;

/**
*
Expand All @@ -41,21 +41,20 @@ public class InterceptorsTest
public void testInterceptors()
{
WeldContainer weld = new Weld().initialize();
BeanManager manager = weld.getBeanManager();

InterceptorTestBean intTestBean = weld.instance().select(InterceptorTestBean.class).get();
Assert.assertNotNull(intTestBean);
assertNotNull(intTestBean);

intTestBean.doSomethingRecorded();
System.out.println(RecordingInterceptor.methodsRecorded);
System.out.println(AggregatingInterceptor.methodsCalled);
Assert.assertTrue(RecordingInterceptor.methodsRecorded.contains("doSomethingRecorded"));
assertTrue(RecordingInterceptor.methodsRecorded.contains("doSomethingRecorded"));

intTestBean.doSomethingRecordedAndAggregated();
System.out.println(RecordingInterceptor.methodsRecorded);
System.out.println(AggregatingInterceptor.methodsCalled);

Assert.assertEquals(1, AggregatingInterceptor.methodsCalled);
assertEquals(1, AggregatingInterceptor.methodsCalled);

shutdownManager(weld);
}
Expand Down
Expand Up @@ -16,14 +16,17 @@
*/
package org.jboss.weld.environment.se.test;


import static org.junit.Assert.assertEquals;

import javax.enterprise.inject.spi.BeanManager;

import org.jboss.weld.environment.se.ShutdownManager;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.jboss.weld.environment.se.test.scopes.Bar;
import org.jboss.weld.environment.se.test.scopes.Foo;
import org.testng.annotations.Test;
import org.junit.Test;

/**
*
Expand All @@ -35,15 +38,16 @@ public class ScopesTest
/**
* Test that decorators work as expected in SE.
*/
@Test(description="WELD-322")
@Test
// WELD-322
public void testScopes()
{

WeldContainer weld = new Weld().initialize();
BeanManager manager = weld.getBeanManager();

assert manager.getBeans(Bar.class).size() == 1;
assert manager.getBeans(Foo.class).size() == 2;
assertEquals(1, manager.getBeans(Bar.class).size());
assertEquals(2, manager.getBeans(Foo.class).size());

shutdownManager(weld);
}
Expand Down
Expand Up @@ -16,6 +16,10 @@
*/
package org.jboss.weld.environment.se.test;

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

import javax.enterprise.inject.spi.BeanManager;

import org.jboss.weld.environment.se.ShutdownManager;
Expand All @@ -26,8 +30,7 @@
import org.jboss.weld.environment.se.test.beans.MainTestBean;
import org.jboss.weld.environment.se.test.beans.ObserverTestBean;
import org.jboss.weld.environment.se.test.beans.ParametersTestBean;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.junit.Test;

/**
*
Expand All @@ -53,17 +56,17 @@ public void testMain()
BeanManager manager = weld.getBeanManager();

MainTestBean mainTestBean = weld.instance().select(MainTestBean.class).get();
Assert.assertNotNull(mainTestBean);
assertNotNull(mainTestBean);

ParametersTestBean paramsBean = mainTestBean.getParametersTestBean();
Assert.assertNotNull(paramsBean);
Assert.assertNotNull(paramsBean.getParameters());
Assert.assertNotNull(paramsBean.getParameters().get(0));
Assert.assertEquals(ARGS[0], paramsBean.getParameters().get(0));
Assert.assertNotNull(paramsBean.getParameters().get(1));
Assert.assertEquals(ARGS[1], paramsBean.getParameters().get(1));
Assert.assertNotNull(paramsBean.getParameters().get(2));
Assert.assertEquals(ARGS[2], paramsBean.getParameters().get(2));
assertNotNull(paramsBean);
assertNotNull(paramsBean.getParameters());
assertNotNull(paramsBean.getParameters().get(0));
assertEquals(ARGS[0], paramsBean.getParameters().get(0));
assertNotNull(paramsBean.getParameters().get(1));
assertEquals(ARGS[1], paramsBean.getParameters().get(1));
assertNotNull(paramsBean.getParameters().get(2));
assertEquals(ARGS[2], paramsBean.getParameters().get(2));

shutdownManager(weld);
}
Expand All @@ -79,11 +82,11 @@ public void testMainEmptyArgs()
BeanManager manager = weld.getBeanManager();

MainTestBean mainTestBean = weld.instance().select(MainTestBean.class).get();
Assert.assertNotNull(mainTestBean);
assertNotNull(mainTestBean);

ParametersTestBean paramsBean = mainTestBean.getParametersTestBean();
Assert.assertNotNull(paramsBean);
Assert.assertNotNull(paramsBean.getParameters());
assertNotNull(paramsBean);
assertNotNull(paramsBean.getParameters());

shutdownManager(weld);
}
Expand All @@ -98,11 +101,11 @@ public void testObservers()
BeanManager manager = weld.getBeanManager();
manager.fireEvent(new CustomEvent());

Assert.assertTrue(ObserverTestBean.isBuiltInObserved());
Assert.assertTrue(ObserverTestBean.isCustomObserved());
Assert.assertTrue(ObserverTestBean.isInitObserved());
assertTrue(ObserverTestBean.isBuiltInObserved());
assertTrue(ObserverTestBean.isCustomObserved());
assertTrue(ObserverTestBean.isInitObserved());

Assert.assertTrue(InitObserverTestBean.isInitObserved());
assertTrue(InitObserverTestBean.isInitObserved());
}

private void shutdownManager(WeldContainer weld)
Expand Down
Expand Up @@ -15,17 +15,16 @@
* limitations under the License.
*/
package org.jboss.weld.environment.se.test;
import static org.junit.Assert.assertEquals;

import org.jboss.weld.environment.se.test.beans.threading.ThreadRunner;
import java.util.ArrayList;

import java.util.List;

import org.jboss.weld.environment.se.ShutdownManager;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
import org.jboss.weld.environment.se.test.beans.threading.ThreadRunner;
import org.junit.Test;

/**
* Tests for ThreadContext, @ThreadScoped and the RunnableDecorator. The
Expand Down
Expand Up @@ -16,6 +16,10 @@
*/
package org.jboss.weld.environment.se.test;

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

import org.jboss.weld.environment.se.ShutdownManager;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
Expand All @@ -24,8 +28,7 @@
import org.jboss.weld.environment.se.test.beans.MainTestBean;
import org.jboss.weld.environment.se.test.beans.ObserverTestBean;
import org.jboss.weld.environment.se.test.beans.ParametersTestBean;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.junit.Test;

/**
*
Expand All @@ -44,11 +47,11 @@ public void testInitialize()
WeldContainer weld = new Weld().initialize();

MainTestBean mainTestBean = weld.instance().select(MainTestBean.class).get();
Assert.assertNotNull(mainTestBean);
assertNotNull(mainTestBean);

ParametersTestBean paramsBean = mainTestBean.getParametersTestBean();
Assert.assertNotNull(paramsBean);
Assert.assertNotNull(paramsBean.getParameters());
assertNotNull(paramsBean);
assertNotNull(paramsBean.getParameters());

shutdownManager(weld);
}
Expand All @@ -66,11 +69,11 @@ public void testObservers()
WeldContainer weld = new Weld().initialize();
weld.event().select(CustomEvent.class).fire(new CustomEvent());

Assert.assertTrue(ObserverTestBean.isBuiltInObserved());
Assert.assertTrue(ObserverTestBean.isCustomObserved());
Assert.assertFalse(ObserverTestBean.isInitObserved());
assertTrue(ObserverTestBean.isBuiltInObserved());
assertTrue(ObserverTestBean.isCustomObserved());
assertFalse(ObserverTestBean.isInitObserved());

Assert.assertFalse(InitObserverTestBean.isInitObserved());
assertFalse(InitObserverTestBean.isInitObserved());
}

private void shutdownManager(WeldContainer weld)
Expand Down
Expand Up @@ -17,15 +17,15 @@

package org.jboss.weld.environment.se.test.beans;

import static org.junit.Assert.assertNotNull;

import java.io.Serializable;
import java.util.List;

import javax.enterprise.context.ApplicationScoped;

import javax.inject.Inject;

import org.jboss.weld.environment.se.bindings.Parameters;
import org.testng.Assert;

/**
*
Expand All @@ -47,7 +47,7 @@ public ParametersTestBean(@Parameters List<String> params)
this.parameters = params;
// even if no args are given, it should will always at least be an empty
// array
Assert.assertNotNull(params);
assertNotNull(params);
}

public List<String> getParameters()
Expand Down

0 comments on commit 267909f

Please sign in to comment.