Skip to content

Commit 7b3521c

Browse files
committed
Do not throw for returning single record methods in MinecraftJar, instead return NULL
1 parent ff1bfa4 commit 7b3521c

File tree

6 files changed

+23
-16
lines changed

6 files changed

+23
-16
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
## [Unreleased]
55

66

7+
## [1.4.6] - 2023-06-07
8+
9+
### Changed
10+
- Do not throw for returning single record methods in MinecraftJar, instead return NULL
11+
12+
713
## [1.4.5] - 2023-06-04
814

915
### Fixed

MinecraftJars.Tests/ProjectTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ public class ProjectTests
1313
public void GetProviderByProject_Success(string providerName)
1414
{
1515
var provider = MinecraftJar.GetProvider(providerName);
16+
Assert.That(provider, Is.Not.Null);
1617

17-
foreach (var project in provider.Projects)
18+
foreach (var project in provider!.Projects)
1819
{
1920
var providerByProject = MinecraftJar.GetProvider(project);
2021
Assert.That(providerByProject, Is.SameAs(provider));
2122

2223
TestContext.Progress.WriteLine("{0}: Provider for project {1} is {2}",
23-
nameof(GetProviderByProject_Success), providerByProject.Name, project.Name);
24+
nameof(GetProviderByProject_Success), providerByProject!.Name, project.Name);
2425
}
2526
}
2627

MinecraftJars.Tests/ProviderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void GetProviderByName_Success()
4848
[TestCase("InvalidProviderName"), Order(5)]
4949
public void GetProviderByName_InvalidProvider(string name)
5050
{
51-
Assert.Throws<InvalidOperationException>(() => MinecraftJar.GetProvider(name));
51+
Assert.That(MinecraftJar.GetProvider(name), Is.Null);
5252
TestContext.Progress.WriteLine("{0}: Provider name {1} invalid", nameof(GetProviderByName_InvalidProvider), name);
5353
}
5454
}

MinecraftJars.Tests/VersionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ private static IEnumerable<string> Projects() =>
1212
[TestCaseSource(nameof(Projects)), Order(1)]
1313
public void GetProjectsByName_Success(string projectName)
1414
{
15-
Assert.DoesNotThrow(() => MinecraftJar.GetProject(projectName));
15+
Assert.That(MinecraftJar.GetProject(projectName), Is.Not.Null);
1616
TestContext.Progress.WriteLine("{0}: Project found by name {1}",
1717
nameof(GetProjectsByName_Success), projectName);
1818
}

MinecraftJars/IMinecraftJar.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public interface IMinecraftJar
1616
IEnumerable<IMinecraftProvider> GetProviders(ProjectGroup projectGroup);
1717

1818
/// <summary>
19-
/// Return a specific provider
19+
/// Return a specific provider, null if not found
2020
/// </summary>
21-
IMinecraftProvider GetProvider(string providerName);
21+
IMinecraftProvider? GetProvider(string providerName);
2222

2323
/// <summary>
24-
/// Return the provider for the provided Project
24+
/// Return the provider for the provided Project, null if not found
2525
/// </summary>
26-
IMinecraftProvider GetProvider(IMinecraftProject project);
26+
IMinecraftProvider? GetProvider(IMinecraftProject project);
2727

2828
/// <summary>
2929
/// Return a list of all projects (e.g. Vanilla, Spigot, etc.)
@@ -36,7 +36,7 @@ public interface IMinecraftJar
3636
IEnumerable<IMinecraftProject> GetProjects(ProjectGroup projectGroup);
3737

3838
/// <summary>
39-
/// Return project by it's name
39+
/// Return project by it's name, null if not found
4040
/// </summary>
41-
IMinecraftProject GetProject(string projectName);
41+
IMinecraftProject? GetProject(string projectName);
4242
}

MinecraftJars/MinecraftJar.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ from project in provider.Projects
4242
select provider;
4343
}
4444

45-
public IMinecraftProvider GetProvider(string providerName)
45+
public IMinecraftProvider? GetProvider(string providerName)
4646
{
4747
return (from provider in GetProviders()
4848
where provider.Name.Equals(providerName)
49-
select provider).Single();
49+
select provider).SingleOrDefault();
5050
}
5151

52-
public IMinecraftProvider GetProvider(IMinecraftProject project)
52+
public IMinecraftProvider? GetProvider(IMinecraftProject project)
5353
{
5454
return (from provider in GetProviders()
5555
where provider.Projects.Contains(project)
56-
select provider).Single();
56+
select provider).SingleOrDefault();
5757
}
5858

5959
public IEnumerable<IMinecraftProject> GetProjects()
@@ -71,11 +71,11 @@ from project in provider.Projects
7171
select project;
7272
}
7373

74-
public IMinecraftProject GetProject(string projectName)
74+
public IMinecraftProject? GetProject(string projectName)
7575
{
7676
return (from provider in GetProviders()
7777
from project in provider.Projects
7878
where project.Name.Equals(projectName)
79-
select project).Single();
79+
select project).SingleOrDefault();
8080
}
8181
}

0 commit comments

Comments
 (0)