Add getValueContentType()

This commit is contained in:
Ashita Prasad
2024-12-06 04:33:13 +05:30
parent 918aefb166
commit 98f1e23a05
2 changed files with 42 additions and 1 deletions

View File

@ -19,4 +19,8 @@ extension MapExtension on Map {
}
return null;
}
String? getValueContentType() {
return this[getKeyContentType()];
}
}

View File

@ -41,7 +41,7 @@ void main() {
expect(mapEx.getKeyContentType(), "Content-Type");
});
test('content-Type present should return true', () {
test('content-Type present', () {
Map<String, String> mapEx = {"Agent": "Test", "content-Type": "x"};
expect(mapEx.getKeyContentType(), "content-Type");
});
@ -72,4 +72,41 @@ void main() {
});
});
});
group('Testing getValueContentType()', () {
test('Content-Type present', () {
Map<String, String> mapEx = {"Agent": "Test", "Content-Type": "x"};
expect(mapEx.getValueContentType(), "x");
});
test('content-Type present', () {
Map<String, String> mapEx = {"Agent": "Test", "content-Type": "x"};
expect(mapEx.getValueContentType(), "x");
});
test('empty should return null', () {
Map<String, String> mapEx = {};
expect(mapEx.getValueContentType(), null);
});
test('No content-type present should return null', () {
Map<String, String> mapEx = {"Agent": "Test"};
expect(mapEx.getValueContentType(), null);
});
test('Different datatype should return null', () {
Map mapEx = {1: "Test"};
expect(mapEx.getValueContentType(), null);
});
test('Mixed datatype but should return x', () {
Map mapEx = {1: "Test", "content-type": "x"};
expect(mapEx.getValueContentType(), "x");
});
test('Multiple occurence should return first', () {
Map mapEx = {1: "Test", "content-Type": "y", "content-type": "x"};
expect(mapEx.getValueContentType(), "y");
});
});
}