Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndiritu committed Oct 4, 2024
1 parent aac05d3 commit bc6edc4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public SerializationWriterFactoryRegistry() {
return contentTypeAssociatedFactories.get(contentTypeWrapper.cleanedContentType);
}
final String cleanedContentType =
getCleanedVendorSpecificContentType(contentTypeWrapper.cleanedContentType);
getCleanedVendorSpecificContentType(vendorSpecificContentType);
if (contentTypeAssociatedFactories.containsKey(cleanedContentType)) {
contentTypeWrapper.cleanedContentType = cleanedContentType;
return contentTypeAssociatedFactories.get(contentTypeWrapper.cleanedContentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void serializesAllValuesInBackedModel() throws IOException {
entity.setId("123");
entity.setOfficeLocation("Nairobi");

// Sets the backing store to be initialized. No properties are dirty
entity.getBackingStore().setIsInitializationCompleted(true);

final String result = KiotaJsonSerialization.serializeAsString(false, entity);
Expand Down Expand Up @@ -136,7 +137,6 @@ void serializesChangedValuesInBackedModel() throws IOException {
final TestBackedModelEntity entity = new TestBackedModelEntity();
entity.setId("123");
entity.setOfficeLocation("Nairobi");

entity.getBackingStore().setIsInitializationCompleted(true);

final String result = KiotaJsonSerialization.serializeAsString(true, entity);
Expand All @@ -150,4 +150,26 @@ void serializesChangedValuesInBackedModel() throws IOException {
new ArrayList<>(Arrays.asList(entity)));
assertEquals("[{}]", collectionResult);
}

@Test
void cleansContentType() throws IOException {
final BackingStoreSerializationWriterProxyFactory
backingStoreSerializationWriterProxyFactory =
new BackingStoreSerializationWriterProxyFactory(
new JsonSerializationWriterFactory());
SerializationWriterFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.put(
_jsonContentType, backingStoreSerializationWriterProxyFactory);

final TestBackedModelEntity entity = new TestBackedModelEntity();
entity.setId("123");
entity.setOfficeLocation("Nairobi");

final String result = KiotaSerialization.serializeAsString("application/json;odata.metadata=minimal", entity);
assertEquals("{\"id\":\"123\",\"officeLocation\":\"Nairobi\"}", result);

// Because onAfterObjectSerialization, returnOnlyChangedValues is set to false & initialization is completed
entity.getBackingStore().setIsInitializationCompleted(false);
final String otherResult = KiotaSerialization.serializeAsString("application/vnd.github.raw+json", entity);
assertEquals("{\"id\":\"123\",\"officeLocation\":\"Nairobi\"}", otherResult);
}
}

0 comments on commit bc6edc4

Please sign in to comment.