From 48197b960ae40a9c094d33433e32662a4d83147b Mon Sep 17 00:00:00 2001 From: AliveDevil Date: Mon, 25 Nov 2024 10:41:00 +0100 Subject: [PATCH] Add test coverage --- .../ApplicationPreferencesTests.cs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/core/src/test/csharp/ch/cyberduck/core/preferences/ApplicationPreferencesTests.cs b/core/src/test/csharp/ch/cyberduck/core/preferences/ApplicationPreferencesTests.cs index de81a26d7c5..9ef96d854ca 100644 --- a/core/src/test/csharp/ch/cyberduck/core/preferences/ApplicationPreferencesTests.cs +++ b/core/src/test/csharp/ch/cyberduck/core/preferences/ApplicationPreferencesTests.cs @@ -1,5 +1,6 @@ using java.util; using NUnit.Framework; +using System.Collections.Generic; namespace Ch.Cyberduck.Core.Preferences; @@ -18,10 +19,36 @@ public void LocaleDisplayNames() } } + [TestCase] + public void PersistsEmptyValue() + { + TestPreferences preferences = new([ + new("test.empty.default", "DONT") + ]); + preferences.load(); + + Assert.AreEqual("DONT", preferences.getDefault("test.empty.default")); + preferences.setProperty("test.empty.default", ""); + Assert.AreEqual("DONT", preferences.getDefault("test.empty.default")); + Assert.AreEqual("", preferences.getProperty("test.empty.default")); + } + public class TestPreferences : ApplicationPreferences { - public TestPreferences() : base(new DefaultLocales(), new PropertyStoreFactory()) + private readonly IEnumerable> testDefaults; + + public TestPreferences(params KeyValuePair[] testDefaults) : base(new DefaultLocales(), new PropertyStoreFactory()) + { + this.testDefaults = testDefaults; + } + + protected override void setDefaults() { + base.setDefaults(); + foreach (var item in testDefaults) + { + setDefault(item.Key, item.Value); + } } } }