Skip to content

Instantly share code, notes, and snippets.

View MounikaMadishetti's full-sized avatar
🎯
Focusing

Mounika Madishetti MounikaMadishetti

🎯
Focusing
  • Intuit
  • Bangalore
View GitHub Profile
@MounikaMadishetti
MounikaMadishetti / URLProtocolStub.swift
Created March 3, 2024 08:25
Create URLProtocol subclass for intercepting network requests
// MARK: - Main Target
final class HTTPClient {
private let session: URLSession
init(session: URLSession = URLSession.shared) {
self.session = session
}
func get(from url: URL) {
// MARK: - Main Target
protocol HTTPSession {
func dataTask(with url: URL, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> HTTPSessionTask
}
protocol HTTPSessionTask {
func resume()
}
@MounikaMadishetti
MounikaMadishetti / SubClass_URLSession.swift
Last active March 2, 2024 18:01
Sample code to demonstrate URLSession subclassing and injecting to the SUT
// MARK: - Main Target
final class HTTPClient {
let session: URLSession
init(session: URLSession = URLSession.shared) {
self.session = session
}
func get(from url: URL) {
session.dataTask(with: URLRequest(url: url)).resume()