<commit_before>import UIKit
import XCTest
@testable import SuperMock

class Tests: XCTestCase {
    
    override func setUp() {
        super.setUp()
        
        SuperMock.beginMocking(NSBundle(forClass: AppDelegate.self))
    }
    
    override func tearDown() {
        super.tearDown()
        
        SuperMock.endMocking()
    }
    
    func testValidGETRequestWithMockReturnsExpectedMockedData() {
        
        let responseHelper = SuperMockResponseHelper.sharedHelper
        
        let url = NSURL(string: "http://mike.kz/")!
        let realRequest = NSMutableURLRequest(URL: url)
        realRequest.HTTPMethod = "GET"
        let mockRequest = responseHelper.mockRequest(realRequest)
        
        let bundle = NSBundle(forClass: AppDelegate.self)
        let pathToExpectedData = bundle.pathForResource("sample", ofType: "html")!

        let expectedData = NSData(contentsOfFile: pathToExpectedData)
        let returnedData = responseHelper.responseForMockRequest(mockRequest)
        
        XCTAssert(expectedData == returnedData, "Expected data not received for mock.")

    }
    
    func testValidPOSTRequestWithMockReturnsExpectedMockedData() {
        
        let responseHelper = SuperMockResponseHelper.sharedHelper
        
        let url = NSURL(string: "http://mike.kz/")!
        let realRequest = NSMutableURLRequest(URL: url)
        realRequest.HTTPMethod = "POST"
        let mockRequest = responseHelper.mockRequest(realRequest)
        
        let bundle = NSBundle(forClass: AppDelegate.self)
        let pathToExpectedData = bundle.pathForResource("samplePOST", ofType: "html")!
        
        let expectedData = NSData(contentsOfFile: pathToExpectedData)
        let returnedData = responseHelper.responseForMockRequest(mockRequest)
        
        XCTAssert(expectedData == returnedData, "Expected data not received for mock.")
        
    }
    
    func testValidRequestWithNoMockReturnsOriginalRequest() {
        let responseHelper = SuperMockResponseHelper.sharedHelper
        
        let url = NSURL(string: "http://nomockavailable.com")!
        let realRequest = NSURLRequest(URL: url)
        let mockRequest = responseHelper.mockRequest(realRequest)
        
        XCTAssert(realRequest == mockRequest, "Original request should be returned when no mock is available.")
    }
    
    func testValidRequestWithMockReturnsDifferentRequest() {
        let responseHelper = SuperMockResponseHelper.sharedHelper
        
        let url = NSURL(string: "http://mike.kz/")!
        let realRequest = NSURLRequest(URL: url)
        let mockRequest = responseHelper.mockRequest(realRequest)
        
        XCTAssert(realRequest != mockRequest, "Different request should be returned when a mock is available.")
    }
    
    func testValidRequestWithMockReturnsFileURLRequest() {
        let responseHelper = SuperMockResponseHelper.sharedHelper
        
        let url = NSURL(string: "http://mike.kz/")!
        let realRequest = NSURLRequest(URL: url)
        let mockRequest = responseHelper.mockRequest(realRequest)
        
        XCTAssert(mockRequest.URL!.fileURL, "fileURL mocked request should be returned when a mock is available.")
    }

}<commit_msg>Added test for record data in file<commit_after>import UIKit
import XCTest
@testable import SuperMock

class Tests: XCTestCase {
    
    override func setUp() {
        super.setUp()
        
        SuperMock.beginMocking(NSBundle(forClass: AppDelegate.self))
    }
    
    override func tearDown() {
        super.tearDown()
        
        SuperMock.endMocking()
    }
    
    func testValidGETRequestWithMockReturnsExpectedMockedData() {
        
        let responseHelper = SuperMockResponseHelper.sharedHelper
        
        let url = NSURL(string: "http://mike.kz/")!
        let realRequest = NSMutableURLRequest(URL: url)
        realRequest.HTTPMethod = "GET"
        let mockRequest = responseHelper.mockRequest(realRequest)
        
        let bundle = NSBundle(forClass: AppDelegate.self)
        let pathToExpectedData = bundle.pathForResource("sample", ofType: "html")!

        let expectedData = NSData(contentsOfFile: pathToExpectedData)
        let returnedData = responseHelper.responseForMockRequest(mockRequest)
        
        XCTAssert(expectedData == returnedData, "Expected data not received for mock.")

    }
    
    func testValidPOSTRequestWithMockReturnsExpectedMockedData() {
        
        let responseHelper = SuperMockResponseHelper.sharedHelper
        
        let url = NSURL(string: "http://mike.kz/")!
        let realRequest = NSMutableURLRequest(URL: url)
        realRequest.HTTPMethod = "POST"
        let mockRequest = responseHelper.mockRequest(realRequest)
        
        let bundle = NSBundle(forClass: AppDelegate.self)
        let pathToExpectedData = bundle.pathForResource("samplePOST", ofType: "html")!
        
        let expectedData = NSData(contentsOfFile: pathToExpectedData)
        let returnedData = responseHelper.responseForMockRequest(mockRequest)
        
        XCTAssert(expectedData == returnedData, "Expected data not received for mock.")
        
    }
    
    func testValidRequestWithNoMockReturnsOriginalRequest() {
        let responseHelper = SuperMockResponseHelper.sharedHelper
        
        let url = NSURL(string: "http://nomockavailable.com")!
        let realRequest = NSURLRequest(URL: url)
        let mockRequest = responseHelper.mockRequest(realRequest)
        
        XCTAssert(realRequest == mockRequest, "Original request should be returned when no mock is available.")
    }
    
    func testValidRequestWithMockReturnsDifferentRequest() {
        let responseHelper = SuperMockResponseHelper.sharedHelper
        
        let url = NSURL(string: "http://mike.kz/")!
        let realRequest = NSURLRequest(URL: url)
        let mockRequest = responseHelper.mockRequest(realRequest)
        
        XCTAssert(realRequest != mockRequest, "Different request should be returned when a mock is available.")
    }
    
    func testValidRequestWithMockReturnsFileURLRequest() {
        let responseHelper = SuperMockResponseHelper.sharedHelper
        
        let url = NSURL(string: "http://mike.kz/")!
        let realRequest = NSURLRequest(URL: url)
        let mockRequest = responseHelper.mockRequest(realRequest)
        
        XCTAssert(mockRequest.URL!.fileURL, "fileURL mocked request should be returned when a mock is available.")
    }
    
    func testRecordDataAsMock() {
        
        let url = NSURL(string: "http://mike.kz/Daniele")!
        let realRequest = NSURLRequest(URL: url)
        
        let responseString = "Something to put into the response field"
        
        let responseHelper = SuperMockResponseHelper.sharedHelper
        let expectedData = responseString.dataUsingEncoding(NSUTF8StringEncoding)!
        
        responseHelper.recordDataForRequest(expectedData, request: realRequest)
        
        let mockRequest = responseHelper.mockRequest(realRequest)
        let returnedData = responseHelper.responseForMockRequest(mockRequest)
        
        XCTAssert(expectedData == returnedData, "Expected data not received for mock.")
        
    }

}
{'fraction_non_alphanumeric': 0.07797405465084184, 'fraction_numerical': 0.0001380071763731714, 'mean_word_length': 2.7568688439606013, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5253414', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1876, 'n_words': 426}