Skip to content

Add unit test to CallableValue & Utility #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/test/java/edu/abhi/poi/excel/CallableValueTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package edu.abhi.poi.excel;

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

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;

import org.junit.Before;
import org.junit.Test;

public class CallableValueTest {

private CallableValue callableValue;

@Before
public void setup(){
callableValue = new CallableValue();
}

@Test
public void setExceptionTest(){
Exception exception=new RuntimeException("Test Message");
callableValue.setException(exception);
assertEquals(exception,callableValue.getException());
}

@Test
public void AnalyzeResultWithEmptyList(){
List<Future<CallableValue>> futures = new ArrayList<>();
assertFalse(CallableValue.analyzeResult(futures));

}
@Test
public void setFailedTrueTest(){
callableValue.setFailed(true);
assertTrue(callableValue.isFailed());
}
@Test
public void setFailedFalseTest(){
callableValue.setFailed(false);
assertFalse(callableValue.isFailed());
}
@Test
public void getDiffContainerWithContentTest(){
String differenceContent="Test difference";
callableValue.getDiffContainer().append(differenceContent);

assertEquals(differenceContent,callableValue.getDiffContainer().toString());
}
@Test
public void getDiffContainerWithoutContentTest(){
StringBuilder testStringBuilder=callableValue.getDiffContainer();
assertTrue(testStringBuilder.isEmpty());
}
@Test
public void setDiffFlagFalseTest(){
callableValue.setDiffFlag(false);
assertFalse(callableValue.isDiffFlag());
}

@Test
public void setDiffFlagTrueTest(){
callableValue.setDiffFlag(true);
assertTrue(callableValue.isDiffFlag());
}

}
34 changes: 34 additions & 0 deletions src/test/java/edu/abhi/poi/excel/UtilityTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package edu.abhi.poi.excel;

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

import java.io.File;
import java.io.IOException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class UtilityTest {
private File tempFile;
@Before
public void setup() throws IOException{
tempFile = File.createTempFile("prefix-", "-suffix");
}
@After
public void tearDown(){
tempFile.delete();
}
@Test
public void deleteIfExistsNonExistingFileTest(){
assertTrue(tempFile.delete());
boolean result = Utility.deleteIfExists(tempFile);
assertFalse(result);
}
@Test
public void deleteIfExistsExistingFileTest(){
boolean result = Utility.deleteIfExists(tempFile);
assertTrue(result);
}
}