Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: aae14ffb51247e14e8a6f51c622d1b1165a532a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*******************************************************************************
 * Copyright (c) 2016, 2018 Red Hat.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Red Hat - Initial Contribution
 *******************************************************************************/

package org.eclipse.linuxtools.internal.docker.ui.testutils;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.linuxtools.docker.core.IRegistryAccount;
import org.eclipse.linuxtools.internal.docker.core.RegistryAccountManager;
import org.eclipse.linuxtools.internal.docker.core.RegistryAccountStorageManager;
import org.mockito.Mockito;

/**
 * Utility class to get mocked instances of {@link RegistryAccountManager}
 */
public class MockRegistryAccountManagerFactory {

	public static MockRegistryAccountManagerBuilder registryAccount(IRegistryAccount registryAccount) {
		return new MockRegistryAccountManagerBuilder().registryAccount(registryAccount);
	}

	public static class MockRegistryAccountManagerBuilder {

		private final List<IRegistryAccount> registryAccounts = new ArrayList<>();

		public MockRegistryAccountManagerBuilder registryAccount(IRegistryAccount registryAccount) {
			registryAccounts.add(registryAccount);
			return this;
		}

		public RegistryAccountManager build() {
			final RegistryAccountStorageManager mockRegistryAccountStorageManager = Mockito
					.mock(RegistryAccountStorageManager.class);
			Mockito.when(mockRegistryAccountStorageManager.getAccounts()).thenReturn(registryAccounts);
			final RegistryAccountManager registryAccountManager = RegistryAccountManager.getInstance();
			registryAccountManager.setStorageManager(mockRegistryAccountStorageManager);
			return registryAccountManager;
		}

	}

}

Back to the top