Skip to content

Commit

Permalink
Fix filedecoderpublisher tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Schwartz-Matthew-bah committed Dec 4, 2018
1 parent b2e68db commit 7b94b3c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ public class FileDecoderPublisher {
private static final Logger logger = LoggerFactory.getLogger(FileDecoderPublisher.class);

private JsonDecoderPublisher jsonDecPub;

@Autowired
public FileDecoderPublisher(OdeProperties odeProperties) {

OdeStringPublisher bsmStringMsgPub = new OdeStringPublisher(odeProperties);
this.jsonDecPub = new JsonDecoderPublisher(bsmStringMsgPub);
}

public void decodeAndPublishFile(
Path filePath,
BufferedInputStream fileInputStream,
ImporterFileType fileType) {
public void decodeAndPublishFile(Path filePath, BufferedInputStream fileInputStream, ImporterFileType fileType) {

String fileName = filePath.toFile().getName();

logger.info("Decoding and publishing file {}", fileName);

try {
logger.info("Decoding {} as json file.", filePath);
jsonDecPub.decodeAndPublish(fileInputStream, fileName, fileType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package us.dot.its.jpo.ode.coder;

import static org.junit.Assert.fail;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.Ignore;
import org.junit.Test;

import mockit.Capturing;
Expand All @@ -18,7 +16,6 @@
import us.dot.its.jpo.ode.coder.stream.JsonDecoderPublisher;
import us.dot.its.jpo.ode.importer.ImporterDirectoryWatcher.ImporterFileType;

@Ignore
public class FileDecoderPublisherTest {

@Injectable
Expand All @@ -28,78 +25,38 @@ public class FileDecoderPublisherTest {
@Capturing
JsonDecoderPublisher capturingJsonDecoderPublisher;
@Capturing
OdeDataPublisher capturedMessagePublisher;

OdeStringPublisher capturingOdeStringPublisher;

@Test
public void hexDecoderShouldDecodeHex() {
try {
public void testNoException() {

new Expectations() {
{
capturingJsonDecoderPublisher.decodeAndPublish((BufferedInputStream) any, anyString, ImporterFileType.OBU_LOG_FILE);
times = 0;
times = 1;
}
};

Path testPath = Paths.get("testFile.hex");
BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 1 }));
testedFileDecoderPublisher.decodeAndPublishFile(testPath, bis, ImporterFileType.OBU_LOG_FILE);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}

}

@Test
public void hexDecoderShouldDecodeText() {
try {
new Expectations() {
{
capturingJsonDecoderPublisher.decodeAndPublish((BufferedInputStream) any, anyString, ImporterFileType.OBU_LOG_FILE);
times = 0;
}
};

Path testPath = Paths.get("testFile.txt");
BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 1 }));
testedFileDecoderPublisher.decodeAndPublishFile(testPath, bis, ImporterFileType.OBU_LOG_FILE);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
}
public void testException() {

@Test
public void jsonDecoderShouldDecodeJson() {
try {
new Expectations() {
{
capturingJsonDecoderPublisher.decodeAndPublish((BufferedInputStream) any, anyString, ImporterFileType.OBU_LOG_FILE);
result = new IOException("testException123");
times = 1;
}
};

Path testPath = Paths.get("testFile.json");
Path testPath = Paths.get("testFile.hex");
BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 1 }));
testedFileDecoderPublisher.decodeAndPublishFile(testPath, bis, ImporterFileType.OBU_LOG_FILE);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
}

@Test
public void binaryDecoderShouldDecodeOther() {
try {
new Expectations() {
{
capturingJsonDecoderPublisher.decodeAndPublish((BufferedInputStream) any, anyString, ImporterFileType.OBU_LOG_FILE);
times = 0;
}
};

Path testPath = Paths.get("testFile.uper");
BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 1 }));
testedFileDecoderPublisher.decodeAndPublishFile(testPath, bis, ImporterFileType.OBU_LOG_FILE);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
}
}

0 comments on commit 7b94b3c

Please sign in to comment.