-
Notifications
You must be signed in to change notification settings - Fork 160
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
Added Junit Tests #3008
Added Junit Tests #3008
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #3008 +/- ##
=============================================
+ Coverage 57.86% 58.28% +0.41%
- Complexity 2596 2598 +2
=============================================
Files 1070 1070
Lines 22863 22863
Branches 2023 2023
=============================================
+ Hits 13230 13326 +96
+ Misses 8693 8603 -90
+ Partials 940 934 -6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Coduz,
I have checked this PR and it looks OK - can you please recheck and merge when possible?
Tests have passed and codeCov has no complaints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sonja-ct ,
I've made some comments. I've commented only first occurrence of many things, but I would like to have that fixed on all places (i.e: all places where:
EventStoreRecordImpl eventStoreRecordImpl = new EventStoreRecordImpl(scopeId);
assertNotNull("Null not expected.", eventStoreRecordImpl);
is done.
There is also a question on why EntityManager
has been mocked.
Thanks,
- Alberto
|
||
for (KapuaId scopeId : scopeIdList) { | ||
EventStoreRecordImpl eventStoreRecordImpl = new EventStoreRecordImpl(scopeId); | ||
assertNotNull("Null not expected.", eventStoreRecordImpl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is always true.
Is not possible to have a null
object after a new
, and if new EventStoreRecordImpl(scopeId)
goes on exception, this assertNotNull
is not executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sonja-ct I suggest that you check here if the created object is of right instance (for example we are expecting "X" instance and if in future this changes so the method returns instance of an object "Y" we will have a test that will check this.
assertNotNull is generally used only when you ahve two outcomes, Null and some not null value. It can also be a part of some assertion list (several assertions that check various things). I agree with @Coduz on this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But a result of a new
is always a notNull
object, unless Exception, which is not covered anyway by this assertNotNull
. This is the same thing as writing assertTrue(true)
.
If new
returns a null
, well Java must be a bit stoned or something 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't also mind to check for the right instance type.
Doing:
EventStoreRecordImpl eventStoreRecordImpl = new EventStoreRecordImpl(scopeId);
assertTrue(eventStoreRecordImpl instence of EventStoreRecordImpl)
is useless for the same reasons.
Also this:
EventStoreRecordImpl eventStoreRecordImpl = new EventStoreRecordImpl(scopeId);
assertTrue(eventStoreRecordImpl instence of EventStoreRecord)
is useless. In both cases, if that isn't true ClassCastException would be throw
n when assigning the new
result to the local variable.
String contextId = "ContextId"; | ||
KapuaId[] scopeIdList = {null, new KapuaIdStatic(BigInteger.ONE), new KapuaIdStatic(BigInteger.TEN), new KapuaIdStatic(BigInteger.ZERO)}; | ||
|
||
for (KapuaId scopeId : scopeIdList) { | ||
EventStoreRecordImpl eventStoreRecordImpl1 = new EventStoreRecordImpl(scopeId); | ||
assertNull("Null expected.", eventStoreRecordImpl1.getContextId()); | ||
eventStoreRecordImpl1.setContextId(contextId); | ||
assertEquals("Expected and actual values should be the same.", contextId, eventStoreRecordImpl1.getContextId()); | ||
eventStoreRecordImpl1.setContextId(null); | ||
assertNull("Null expected.", eventStoreRecordImpl1.getContextId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that testing for different values of scopeId is not meaningful.
We want to test only once test and get.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. We can test only with "null" and BigInteger.ONE for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes good
EventStoreRecordImpl eventStoreRecordImpl3 = new EventStoreRecordImpl(eventStoreRecord); | ||
assertEquals("Expected and actual values should be the same.", "contextId", eventStoreRecordImpl3.getContextId()); | ||
eventStoreRecordImpl3.setContextId(contextId); | ||
assertEquals("Expected and actual values should be the same.", contextId, eventStoreRecordImpl3.getContextId()); | ||
eventStoreRecordImpl3.setContextId(null); | ||
assertNull("Null expected.", eventStoreRecordImpl3.getContextId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clone method has been already been tested in eventStoreRecordImplTest3
, if I'm correct.
So also this is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Coduz here we are checking if the contextId is null and in the "eventStoreRecordImplTest3" we check if the expected and actual values are the same, so these are two different cases. If I am seeing right.
|
||
@Test | ||
public void eventStoreDAOTest() throws Exception { | ||
Constructor<EventStoreDAO> eventStoreDAO = EventStoreDAO.class.getDeclaredConstructor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EventStoreDAO and other EntityDAO are static and testing the instantiation is not needed.
import java.util.List; | ||
|
||
@Category(JUnitTests.class) | ||
public class EventStoreDAOTest extends Assert { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why mock DAO methods when there is an actual implementation available and working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Coduz we should always mock as much methods as possible to isolate unit test as much as possible.
We don't want actual implementation of other methods to imterfere with our Unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
for (KapuaId scopeId : scopeIdList) { | ||
EventStoreRecordImpl eventStoreRecordImpl = new EventStoreRecordImpl(scopeId); | ||
assertNotNull("Null not expected.", eventStoreRecordImpl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sonja-ct I suggest that you check here if the created object is of right instance (for example we are expecting "X" instance and if in future this changes so the method returns instance of an object "Y" we will have a test that will check this.
assertNotNull is generally used only when you ahve two outcomes, Null and some not null value. It can also be a part of some assertion list (several assertions that check various things). I agree with @Coduz on this one.
String contextId = "ContextId"; | ||
KapuaId[] scopeIdList = {null, new KapuaIdStatic(BigInteger.ONE), new KapuaIdStatic(BigInteger.TEN), new KapuaIdStatic(BigInteger.ZERO)}; | ||
|
||
for (KapuaId scopeId : scopeIdList) { | ||
EventStoreRecordImpl eventStoreRecordImpl1 = new EventStoreRecordImpl(scopeId); | ||
assertNull("Null expected.", eventStoreRecordImpl1.getContextId()); | ||
eventStoreRecordImpl1.setContextId(contextId); | ||
assertEquals("Expected and actual values should be the same.", contextId, eventStoreRecordImpl1.getContextId()); | ||
eventStoreRecordImpl1.setContextId(null); | ||
assertNull("Null expected.", eventStoreRecordImpl1.getContextId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. We can test only with "null" and BigInteger.ONE for example.
import java.util.List; | ||
|
||
@Category(JUnitTests.class) | ||
public class EventStoreDAOTest extends Assert { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Coduz we should always mock as much methods as possible to isolate unit test as much as possible.
We don't want actual implementation of other methods to imterfere with our Unit tests.
EventStoreRecordImpl eventStoreRecordImpl3 = new EventStoreRecordImpl(eventStoreRecord); | ||
assertEquals("Expected and actual values should be the same.", "contextId", eventStoreRecordImpl3.getContextId()); | ||
eventStoreRecordImpl3.setContextId(contextId); | ||
assertEquals("Expected and actual values should be the same.", contextId, eventStoreRecordImpl3.getContextId()); | ||
eventStoreRecordImpl3.setContextId(null); | ||
assertNull("Null expected.", eventStoreRecordImpl3.getContextId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Coduz here we are checking if the contextId is null and in the "eventStoreRecordImplTest3" we check if the expected and actual values are the same, so these are two different cases. If I am seeing right.
3c80046
to
30e5884
Compare
Hey @Coduz, |
Added Junit tests for EventStoreDAO class Added Junit tests for EventStoreFactoryImpl class Added Junit tests for EventStoreRecordImpl class Added Junit tests for EventStoreServiceImpl class Signed-off-by: Sonja <sonja.matic@comtrade.com>
Added Junit tests for EventStoreDAO class
Added Junit tests for EventStoreFactoryImpl class
Added Junit tests for EventStoreRecordImpl class
Added Junit tests for EventStoreServiceImpl class
Signed-off-by: Sonja sonja.matic@comtrade.com
Related Issue
/
Description of the solution adopted
/
Screenshots
/
Any side note on the changes made
/