-
Notifications
You must be signed in to change notification settings - Fork 6
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
CARDS-2154: cards-utils tests #1418
base: dev
Are you sure you want to change the base?
Conversation
* @version $Id $ | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class ResourceToCSVAdapterFactoryTest |
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.
More tests:
getAdapterWithNoProcessorsReturnsResourcePath
- has an empty list of processorsgetAdapterUsesFirstProcessorThatCanProcess
- has 3 processors, first cannot process, check second's output is used, verify first's and third'sserialize
is never invoked
} | ||
|
||
@Test | ||
public void getAdapterForResourceAdaptableObjectReturnsResourcePath() |
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.
public void getAdapterForResourceAdaptableObjectReturnsResourcePath() | |
public void getAdapterForUnsupportedResourceReturnsResourcePath() |
when(processor.isEnabledByDefault(adaptable)).thenReturn(true); | ||
when(processor.getName()).thenReturn("name"); | ||
when(processor.canProcess(adaptable)).thenReturn(true); |
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.
These lines are the same in all 3 tests, they should be moved in a mockWorkingProcessor
method.
ResourceMetadata resourceMetadata = mock(ResourceMetadata.class); | ||
when(adaptable.getResourceMetadata()).thenReturn(resourceMetadata); |
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 code seems useless to me; the fact that it is actually needed here suggests that the actual code can be improved. Try moving the adaptTo(Node.class)
line earlier in the method, and add a check for null.
Normally, in test-driven development, the tests are supposed to influence the code, not the other way around, so you should feel free to also change the code being tested when you feel that it can be improved, not just write tests that perfectly match the existing code.
* @version $Id $ | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class ResourceToJsonAdapterFactoryTest |
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.
More tests:
getAdapterUsesAllSupportedAndEnabledProcessors
- receives a list of processors that either support or not the resource, and that are either enabled or disabled by defaultgetAdapterSortsProcessors
- receives a list of processors in the wrong order; to make the order validation easier to check, write a simple class that receives a priority and 2 integersa
andb
in its constructor, and implementsResourceJsonProcessor.processProperty
asreturn Json.createValue(input == null ? b : ((JsonNumber) input).intValue() * a + b);
; instantiate 4 such processors with different prime values fora
andb
, and serialize a number; make sure the output matches the expected resultgetAdapterWithNoProcessorsReturnsEmptyJsonObject
- uses an empty list of processorsgetAdapterWithNoSupportedProcessorsReturnsEmptyJsonObject
- uses one processor that cannot process the resourcegetAdapterWithRecursiveReferencesUsesResourcePathForNestedReferences
getAdapterUsesResourceSelectorsToDisableDefaultProcessors
getAdapterUsesResourceSelectorsToEnableProcessors
getAdapterWithBothEnableAndDisableSelectorsPrioritizesEnable
} | ||
|
||
@Test | ||
public void isEnabledByDefaultTest() |
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.
Oh, I think each processor needs this test, even if the method is not overridden in a class, just to check that it is indeed false.
Property property = node.getProperty("jcr:baseVersion"); | ||
JsonValue json = Json.createValue(FORM_TYPE); | ||
JsonValue jsonValue = this.dereferenceProcessor.processProperty(node, property, json, this::serializeNode); | ||
assertNotNull(jsonValue); |
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 needs an assertEquals
check as well.
assertEquals(property.getNode().getPath(), ((JsonString) jsonValue).getString());
assertTrue(jsonObject.containsKey("@path")); | ||
assertEquals(Json.createValue(TEST_FORM_PATH), jsonObject.getJsonString("@path")); | ||
assertTrue(jsonObject.containsKey("@name")); | ||
assertEquals(Json.createValue("f1"), jsonObject.getJsonString("@name")); |
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 not the simpler:
assertEquals("f1", jsonObject.getString("@name"));
} | ||
|
||
@Test | ||
public void leaveAddsPathAndNameAndReferencedParameters() throws RepositoryException |
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 would split this into 2 methods:
leaveAddsPathAndNameParameters
leaveAddsReferencedParameter
Also, I would test the reference for 2 different nodes, the form (for false
) and the questionnaire (for true
).
* @version $Id $ | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class SimpleProcessorTest |
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 is missing a positive test: processPropertyReturnsInput
.
|
jacoco.zip |
tests for DenyScriptsSlingPostProcessor
tests for ContentTypeSetter and StatusCodeSetter
tests for ResourceToCSVAdapterFactory
tests for ResourceToJsonAdapterFactory, ResourceToMarkdownAdspterFactory, ResourceToTextAdapterFactory
tests for BareProcessor
tests for DeepProcessor, DereferenceProcessor, IdentificationProcessor, PropertiesProcessor, SimpleProcessor
fixes for ResourceToCSVAdapterFactory
fixes for ResourceToMarkdownAdapterFactory
fixes for ResourceToTextAdapterFactory
tests for CSVString
fixes for DenyScriptsSlingPostProcessorTest
fixes for BareProcessorTest
fixes for DeepProcessorTest, DeferenceProcessorTest, PropertiesProcessorTest, PropertiesProcessorTest
fixes for IdentificationProcessorTest
fixes for SimpleProcessorTest
fixes for ResourceToJsonAdapterFactoryTest
… SimpleProcessor, and DereferenceProcessor
3bb94da
to
fa83ebe
Compare
No description provided.