Skip to content

Commit

Permalink
UnitTests: fix Hashable and Equatable
Browse files Browse the repository at this point in the history
  • Loading branch information
BLeeEZ committed May 28, 2021
1 parent fe28482 commit a7c0ad0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
5 changes: 0 additions & 5 deletions Amperfy/Storage/EntityWrappers/AbstractLibraryEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,5 @@ public class AbstractLibraryEntity {
}
return img
}

public func isEqual(_ object: Any?) -> Bool {
guard let object = object as? AbstractLibraryEntity else { return false }
return managedObject == object.managedObject
}

}
13 changes: 9 additions & 4 deletions Amperfy/Storage/EntityWrappers/Album.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ public class Album: AbstractLibraryEntity, SongContainable {
}
return Artwork.defaultImage
}

override public func isEqual(_ object: Any?) -> Bool {
guard let object = object as? Album else { return false }
return managedObject == object.managedObject

}

extension Album: Hashable, Equatable {
public static func == (lhs: Album, rhs: Album) -> Bool {
return lhs.managedObject == rhs.managedObject && lhs.managedObject == rhs.managedObject
}

public func hash(into hasher: inout Hasher) {
hasher.combine(managedObject)
}
}
13 changes: 9 additions & 4 deletions Amperfy/Storage/EntityWrappers/Artist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@ public class Artist: AbstractLibraryEntity, SongContainable {
if managedObject.syncInfo != newValue?.managedObject { managedObject.syncInfo = newValue?.managedObject }
}
}

override public func isEqual(_ object: Any?) -> Bool {
guard let object = object as? Artist else { return false }
return managedObject == object.managedObject

}

extension Artist: Hashable, Equatable {
public static func == (lhs: Artist, rhs: Artist) -> Bool {
return lhs.managedObject == rhs.managedObject && lhs.managedObject == rhs.managedObject
}

public func hash(into hasher: inout Hasher) {
hasher.combine(managedObject)
}
}
5 changes: 0 additions & 5 deletions Amperfy/Storage/EntityWrappers/Song.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ public class Song: AbstractLibraryEntity, Identifyable {
}
return false
}

override public func isEqual(_ object: Any?) -> Bool {
guard let object = object as? Song else { return false }
return managedObject == object.managedObject
}

}

Expand Down
6 changes: 4 additions & 2 deletions AmperfyTests/Cases/Player/MusicPlayerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class MusicPlayerTest: XCTestCase {
var storage: LibraryStorage!
var mockAlertDisplayer: MOCK_AlertDisplayable!
var eventLogger: EventLogger!
var userStatistics: UserStatistics!
var songDownloader: MOCK_SongDownloader!
var backendPlayer: BackendAudioPlayer!
var playerData: PlayerData!
Expand All @@ -80,9 +81,10 @@ class MusicPlayerTest: XCTestCase {
mockAVPlayer = MOCK_AVPlayer()
mockAlertDisplayer = MOCK_AlertDisplayable()
eventLogger = EventLogger(alertDisplayer: mockAlertDisplayer, persistentContainer: cdHelper.persistentContainer)
backendPlayer = BackendAudioPlayer(mediaPlayer: mockAVPlayer, eventLogger: eventLogger, songDownloader: songDownloader, songCache: storage)
userStatistics = storage.getUserStatistics(appVersion: "")
backendPlayer = BackendAudioPlayer(mediaPlayer: mockAVPlayer, eventLogger: eventLogger, songDownloader: songDownloader, songCache: storage, userStatistics: userStatistics)
playerData = storage.getPlayerData()
testPlayer = MusicPlayer(coreData: playerData, downloadManager: songDownloader, backendAudioPlayer: backendPlayer)
testPlayer = MusicPlayer(coreData: playerData, downloadManager: songDownloader, backendAudioPlayer: backendPlayer, userStatistics: userStatistics)

guard let songCachedFetched = storage.getSong(id: "36") else { XCTFail(); return }
songCached = songCachedFetched
Expand Down

0 comments on commit a7c0ad0

Please sign in to comment.