Skip to content

Commit

Permalink
Merge branch 'Ode-levesque-unittesting' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tonychen091 committed Oct 17, 2017
2 parents 5fbe68d + 58c9741 commit 2be6255
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public void processAndBackupFile(Path filePath, Path backupDir) {
* remove line below when asn1_codec is integrated
*/
try (InputStream inputStream = new FileInputStream(filePath.toFile())) {
BufferedInputStream bis = new BufferedInputStream(inputStream, odeProperties.getImportProcessorBufferSize());
decoderPublisherManager.decodeAndPublishFile(filePath, bis, fileType);
bis = new BufferedInputStream(inputStream, odeProperties.getImportProcessorBufferSize());
BufferedInputStream bis = new BufferedInputStream(inputStream, odeProperties.getImportProcessorBufferSize());
decoderPublisherManager.decodeAndPublishFile(filePath, bis, fileType);

} catch (Exception e) {
logger.error("Unable to open or process file: " + filePath, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.nio.file.Path;
import java.util.Iterator;

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

import mockit.Capturing;
Expand Down Expand Up @@ -42,9 +43,13 @@ public class ImporterProcessorTest {
@Capturing
OdeFileUtils capturingOdeFileUtils;



@Mocked
Path mockFile;

@Mocked
Path mockFileBackup;

@Injectable
Path injectableDir;
@Injectable
Expand All @@ -67,7 +72,7 @@ public void processExistingFilesShouldCatchExceptionFailedToCreateStream() {

testImporterProcessor.processDirectory(injectableDir, injectableBackupDir);
}

@Test
public void processExistingFilesShouldProcessOneFile(@Mocked DirectoryStream<Path> mockDirectoryStream,
@Mocked Iterator<Path> mockIterator) {
Expand Down Expand Up @@ -111,18 +116,19 @@ public void processAndBackupFileFileShouldCatchExceptionStream() {
@Test
public void processAndBackupFileShouldOdeFileUtilsException() {



try {
new Expectations(FileInputStream.class, BufferedInputStream.class) {
new Expectations(FileInputStream.class) {
{
new BufferedInputStream((InputStream) any, anyInt);
result = null;
new FileInputStream((File) any);
result = null;
capturingFileDecoderPublisher.decodeAndPublishFile((Path) any, (BufferedInputStream) any, ImporterFileType.BSM_LOG_FILE);
times = 1;
result = null;


OdeFileUtils.backupFile((Path) any, (Path) any);
result = new IOException("testException123");
times = 1;


}
};
} catch (Exception e) {
Expand All @@ -131,4 +137,5 @@ public void processAndBackupFileShouldOdeFileUtilsException() {
testImporterProcessor.processAndBackupFile(mockFile, injectableBackupDir);
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package us.dot.its.jpo.ode.udp.controller;

//import static org.junit.Assert.assertEquals;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
Expand All @@ -20,8 +22,12 @@ public class ServiceManagerTest {
@Tested
ServiceManager testServiceManager;

@Mocked
Executors mockExecutors;

@Injectable
ThreadFactory mockThreadFactory;


@Test
public void receiverSubmitCallsExecutorService(@Capturing Executors mockExecutors,
Expand All @@ -40,16 +46,17 @@ public void receiverSubmitCallsExecutorService(@Capturing Executors mockExecutor
testServiceManager.submit(mockAbstractUdpReceiverPublisher);

}

public void depositorCallsSubscribe(@Mocked AbstractSubscriberDepositor mockAbstractSubscriberDepositor) {
@Test
public void depositorCallsSubscribe(@Mocked AbstractSubscriberDepositor mockAbstractSubscriberDepositor, @Mocked String mockString) {

new Expectations() {
{
mockAbstractSubscriberDepositor.subscribe(anyString);
times = 1;
}
};

testServiceManager.submit(mockAbstractSubscriberDepositor);
testServiceManager.submit(mockAbstractSubscriberDepositor, mockString);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,13 @@ public void shouldReturnNamedThread(@Injectable Thread testThread) {
assertEquals(expectedName, actualThread.getName());
}

@Test
public void shouldSetThreadName(@Injectable Thread testThreadTwo) {
Thread actualThreadTwo = testUdpServiceThreadFactory.newThread(testThreadTwo);
testUdpServiceThreadFactory.setThreadName(expectedName);

assertEquals(expectedName, actualThreadTwo.getName());

}

}

0 comments on commit 2be6255

Please sign in to comment.