/*
 * The MIT License
 *
 * Copyright (c) 2011-2012, CloudBees, Inc., Stephen Connolly.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.cloudbees.plugins.credentials;

import com.cloudbees.plugins.credentials.impl.DummyCredentials;
import org.apache.commons.io.FileUtils;
import org.jvnet.hudson.test.HudsonTestCase;

public class SystemCredentialsProviderTest extends HudsonTestCase {

    public void testSaveAndLoad() throws Exception {
        assertTrue(CredentialsProvider.lookupCredentials(Credentials.class).isEmpty());
        SystemCredentialsProvider.getInstance().save();
        assertTrue(new SystemCredentialsProvider().getCredentials().isEmpty());
        SystemCredentialsProvider.getInstance().getCredentials().add(
                new DummyCredentials(CredentialsScope.SYSTEM, "foo", "bar"));
        assertFalse(CredentialsProvider.lookupCredentials(Credentials.class).isEmpty());
        assertTrue(new SystemCredentialsProvider().getCredentials().isEmpty());
        SystemCredentialsProvider.getInstance().save();
        assertFalse(new SystemCredentialsProvider().getCredentials().isEmpty());
    }

    public void testMalformedInput() throws Exception {
        assertTrue(CredentialsProvider.lookupCredentials(Credentials.class).isEmpty());
        SystemCredentialsProvider.getInstance().getCredentials().add(
                new DummyCredentials(CredentialsScope.SYSTEM, "foo", "bar"));
        assertFalse(CredentialsProvider.lookupCredentials(Credentials.class).isEmpty());
        assertTrue(new SystemCredentialsProvider().getCredentials().isEmpty());
        SystemCredentialsProvider.getInstance().save();
        assertFalse(new SystemCredentialsProvider().getCredentials().isEmpty());
        FileUtils.writeStringToFile(SystemCredentialsProvider.getConfigFile().getFile(), "<<barf>>");
        assertTrue(new SystemCredentialsProvider().getCredentials().isEmpty());
    }

    public void testSmokes() throws Exception {
        assertEquals(true, !CredentialsProvider.allCredentialsDescriptors().isEmpty());
        assertNotNull(SystemCredentialsProvider.getInstance().getDescriptor());
        assertNotNull(SystemCredentialsProvider.getInstance().getCredentials());
    }

}

@@ -1324,110 +1324,376 @@
 rg.j
-vnet.hudson.test.HudsonTestCase;%0A%0Apublic class SystemCredentialsProviderTest extends HudsonTestCase %7B%0A
+unit.Rule;%0Aimport org.junit.Test;%0Aimport org.jvnet.hudson.test.JenkinsRule;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertNotNull;%0Aimport static org.junit.Assert.assertTrue;%0A%0Apublic class SystemCredentialsProviderTest %7B%0A%0A    @Rule%0A    public JenkinsRule r = new JenkinsRule();%0A%0A    @Test
 %0A   
@@ -1705,21 +1705,17 @@
 ic void 
-testS
+s
 aveAndLo
@@ -2415,32 +2415,42 @@
 mpty());%0A    %7D%0A%0A
+    @Test%0A
     public void 
@@ -2453,13 +2453,9 @@
 oid 
-testM
+m
 alfo
@@ -3212,24 +3212,34 @@
 ());%0A    %7D%0A%0A
+    @Test%0A
     public v
@@ -3246,13 +3246,9 @@
 oid 
-testS
+s
 moke

Migrate from HudsonTestCase to JenkinsRule