I looked at other jUnit null point exceptions and none of them are suitable for what I am experiencing. I am running Eclipse 4.3.1 with Ubuntu 12.04.
I created a jUnit class with the Eclipse wizard and thought I was following the whole tutorial. The code:
import static org.junit.Assert.*;
import java.util.concurrent.TimeUnit;
import java.io.IOException;
import org.openhab.action.videoanalytics.AwarenessTypes.*;
import org.junit.Test;
public class ThreeMinuteRun {
String cameraId = "cam1test";
String videoStream = "http://xxx.xxx.xxx.xxx/mjpg/video.mjpg";
String format = "MJPG";
MotionDetectionType motionType= MotionDetectionType.basic;
AwarenessAnalytics AA = new AwarenessAnalytics();
String maskFilename = "/home/will/odev/MotionDetect/src/main/resources/DrivewayMaskWhite.png";
MotionDetectionState motionDetectionState = MotionDetectionState.on;
String directoryStore = "/media/PENDRIVE/alertImageTest/";
@Test
public void testSetVideoSource() {
try {
AA.setVideoSource(cameraId, videoStream, format, motionType);
} catch (IOException e) {
fail("IOException in setVideoSource");
}
}
@Test
public void testAddListener() {
AA.addListener(new DetectionListener());
}
@Test
public void testSetFramesToExaminePerSecond() {
AA.setFramesToExaminePerSecond(cameraId, 1);
}
@Test
public void testSetMotionDetectionType() {
AA.setMotionDetectionType(cameraId, motionType);
}
@Test
public void testSetImageStoreLocation() {
AA.setImageStoreLocation(directoryStore);;
}
@Test
public void testSetsecsUntilMotionCeasedOption() {
AA.setsecsUntilMotionCeasedOption(7);
}
@Test
public void testSetSizeSensitivity() {
AA.setSizeSensitivity(cameraId, 4);
}
@Test
public void testSetDebugState() {
AA.setDebugState(true, 10);
}
@Test
public void testSetMotionDetectionState() {
AA.setMotionDetectionState(cameraId, motionDetectionState);
}
@Test
public void testSetLightFalseAlarmAdjustment() {
AA.setLightFalseAlarmAdjustment(cameraId, 5);
}
@Test
public void testSetMaskImage() {
AA.setMaskImage(cameraId, maskFilename);
}
@Test
public void testSetMaskState() {
AA.setMaskState(cameraId, true);
}
@Test
public void testGetAlertImages() {
fail("Not yet implemented");
}
@Test
public void testGetAlertVideo() {
fail("Not yet implemented");
}
@Test
public void testStart() {
AA.start();
try {
TimeUnit.SECONDS.sleep(360000);
} catch (Exception e) {
System.out.println(e);
}
}
@Test
public void testStop() {
AA. stop();
}
}
The msg error I get is pretty concise;
An internal error occurred during: "Launching ThreeMinuteRun (1)".
java.lang.NullPointerException
This three-minute tour has turned into a 3-hour tour ...
Thoughts?
EDIT:
I changed the setVideoSource preamble to @Before (although it is not required to run before most other calls), and I changed the Start preamble to @After, which requires you to first set the video source.
@Before
public void testSetVideoSource() {
try {
AA.setVideoSource(cameraId, videoStream, format, motionType);
} catch (IOException e) {
fail("IOException in setVideoSource");
}
}
@After
public void testStart() {
AA.start();
try {
TimeUnit.SECONDS.sleep(360000);
} catch (Exception e) {
System.out.println(e);
}
}
I still get the same exception.
Just a note: I have a non-jUnit test driver that currently works great, I'm trying to improve my skills (and add discipline) to
Awareness - ( ), VideoAnalytics ( ). , jUnit, , .
2:
jUnit, , AwarenessAnalytic ( , ).
3:
testSetVideoSource init, (- ).
@Before
public void init() {
try {
AA.setVideoSource(cameraId, videoStream, format, motionType);
} catch (IOException e) {
fail("IOException in setVideoSource");
}
}
4:
, , :
@Before
public void init() {
try {
AA.setVideoSource(cameraId, videoStream, format, motionType);
} catch (IOException e) {
fail("IOException in setVideoSource");
}
}
@Test
public void testAddListener() {
AA.addListener(new DetectionListener());
}
@After
public void testStart() {
AA.start();
try {
TimeUnit.SECONDS.sleep(360000);
} catch (Exception e) {
System.out.println(e);
}
}
, , , JUnit "(1)";
An internal error occurred during: "Launching ThreeMinuteRunSimple".
java.lang.NullPointerException
Debug, JUnit, , , - .
?