mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:33:01 +08:00
Add fallback case for GetDisplayString
if called on a null reference
This commit is contained in:
parent
a754b40a8a
commit
98dcf487da
@ -10,19 +10,28 @@ using osu.Game.Rulesets;
|
|||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace osu.Game.Tests.Models
|
namespace osu.Game.Tests.Models
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class DisplayStringTest
|
public class DisplayStringTest
|
||||||
{
|
{
|
||||||
|
[Test]
|
||||||
|
public void TestNull()
|
||||||
|
{
|
||||||
|
IBeatmapSetInfo? beatmap = null;
|
||||||
|
Assert.That(beatmap.GetDisplayString(), Is.EqualTo("null"));
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestBeatmapSet()
|
public void TestBeatmapSet()
|
||||||
{
|
{
|
||||||
var mock = new Mock<IBeatmapSetInfo>();
|
var mock = new Mock<IBeatmapSetInfo>();
|
||||||
|
|
||||||
mock.Setup(m => m.Metadata.Artist).Returns("artist");
|
mock.Setup(m => m.Metadata!.Artist).Returns("artist");
|
||||||
mock.Setup(m => m.Metadata.Title).Returns("title");
|
mock.Setup(m => m.Metadata!.Title).Returns("title");
|
||||||
mock.Setup(m => m.Metadata.Author.Username).Returns("author");
|
mock.Setup(m => m.Metadata!.Author.Username).Returns("author");
|
||||||
|
|
||||||
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title (author)"));
|
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title (author)"));
|
||||||
}
|
}
|
||||||
@ -32,9 +41,9 @@ namespace osu.Game.Tests.Models
|
|||||||
{
|
{
|
||||||
var mock = new Mock<IBeatmapSetInfo>();
|
var mock = new Mock<IBeatmapSetInfo>();
|
||||||
|
|
||||||
mock.Setup(m => m.Metadata.Artist).Returns("artist");
|
mock.Setup(m => m.Metadata!.Artist).Returns("artist");
|
||||||
mock.Setup(m => m.Metadata.Title).Returns("title");
|
mock.Setup(m => m.Metadata!.Title).Returns("title");
|
||||||
mock.Setup(m => m.Metadata.Author.Username).Returns(string.Empty);
|
mock.Setup(m => m.Metadata!.Author.Username).Returns(string.Empty);
|
||||||
|
|
||||||
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title"));
|
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title"));
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ namespace osu.Game.Extensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fallback in case none of the above happens to match.
|
// fallback in case none of the above happens to match.
|
||||||
result ??= model.ToString();
|
result ??= model?.ToString() ?? @"null";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user