CARDS-2154: cards-utils tests - #1418
Conversation
| * @version $Id $ | ||
| */ | ||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class ResourceToCSVAdapterFactoryTest |
There was a problem hiding this comment.
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'sserializeis never invoked
| } | ||
|
|
||
| @Test | ||
| public void getAdapterForResourceAdaptableObjectReturnsResourcePath() |
There was a problem hiding this comment.
| 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.
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.
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.
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 integersaandbin its constructor, and implementsResourceJsonProcessor.processPropertyasreturn Json.createValue(input == null ? b : ((JsonNumber) input).intValue() * a + b);; instantiate 4 such processors with different prime values foraandb, 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 resourcegetAdapterWithRecursiveReferencesUsesResourcePathForNestedReferencesgetAdapterUsesResourceSelectorsToDisableDefaultProcessorsgetAdapterUsesResourceSelectorsToEnableProcessorsgetAdapterWithBothEnableAndDisableSelectorsPrioritizesEnable
| } | ||
|
|
||
| @Test | ||
| public void isEnabledByDefaultTest() |
There was a problem hiding this comment.
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.
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.
Why not the simpler:
assertEquals("f1", jsonObject.getString("@name"));
| } | ||
|
|
||
| @Test | ||
| public void leaveAddsPathAndNameAndReferencedParameters() throws RepositoryException |
There was a problem hiding this comment.
I would split this into 2 methods:
leaveAddsPathAndNameParametersleaveAddsReferencedParameter
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.
This is missing a positive test: processPropertyReturnsInput.
|
|
|
jacoco.zip |
3bb94da to
fa83ebe
Compare
fa83ebe to
d08ad09
Compare
d08ad09 to
4c9df54
Compare
Modernize the revived tests and complete the module coverage to 100%: - migrate the tests to the current platform APIs: jakarta.json, SlingJakartaHttpServletRequest/Response, the jakartaResponse binding, Mockito 5, sling-mock 4 - drop the Mockito runner in favor of plain mocks with reflection injection, since concurrently running runners collide on Mockito's global listener registry under the parallel surefire configuration - raise the sling-mock resource resolver factory timeout, the default 500ms is flaky when several Oak-backed contexts start in parallel - add tests for the previously uncovered classes: SelectorServlet, DateUtils, SelectorDetails, BaseFilterFactory, DataFilter and the serialization SPI default methods, DefaultDataFilters(Parser), DefaultOptionsProcessor, ExcludeDefaultPropertiesProcessor, ImportableProcessor, ReferencedProcessor, PreventVersionOverrideServletFilter - fix a latent NPE: SelectorDetails built through the vararg options constructor with fewer than two option strings left the options array null, crashing SelectorServlet's getOptions().length - remove an unreachable branch in DateUtils.parseDateTime, parseBest either returns one of the two queried types or throws - remove the module's coverage exemption, restoring the default 1.00 required instruction coverage ratio
4c9df54 to
b09a627
Compare
| } | ||
|
|
||
| @Test | ||
| public void getAdapterUsesFirstProcessorThatCanProcess() throws IllegalAccessException |
| } | ||
|
|
||
| @Test | ||
| public void getAdapterForResourceAdaptableObjectReturnsSerializedAdapter() throws IllegalAccessException |
| } | ||
|
|
||
| @Test | ||
| public void getAdapterUsesFirstProcessorThatCanProcess() throws IllegalAccessException |
| } | ||
|
|
||
| @Test | ||
| public void getAdapterForResourceAdaptableObjectReturnsSerializedAdapter() throws IllegalAccessException |
No description provided.