|
3 | 3 | import static org.junit.Assert.assertEquals; |
4 | 4 | import static org.junit.Assert.assertFalse; |
5 | 5 | import static org.junit.Assert.assertTrue; |
| 6 | +import static org.mockito.Matchers.any; |
| 7 | +import static org.mockito.Matchers.eq; |
| 8 | +import static org.powermock.api.mockito.PowerMockito.*; |
6 | 9 |
|
7 | 10 | import fi.helsinki.cs.tmc.cli.Application; |
8 | 11 | import fi.helsinki.cs.tmc.cli.analytics.AnalyticsFacade; |
|
13 | 16 | import fi.helsinki.cs.tmc.cli.io.WorkDir; |
14 | 17 | import fi.helsinki.cs.tmc.core.TmcCore; |
15 | 18 | import fi.helsinki.cs.tmc.core.domain.Organization; |
| 19 | +import fi.helsinki.cs.tmc.core.domain.ProgressObserver; |
16 | 20 | import fi.helsinki.cs.tmc.core.holders.TmcSettingsHolder; |
17 | 21 | import fi.helsinki.cs.tmc.langs.util.TaskExecutorImpl; |
18 | 22 | import fi.helsinki.cs.tmc.spyware.EventSendBuffer; |
19 | 23 | import fi.helsinki.cs.tmc.spyware.EventStore; |
20 | 24 | import fi.helsinki.cs.tmc.spyware.SpywareSettings; |
21 | 25 | import org.junit.Before; |
22 | 26 | import org.junit.Test; |
| 27 | +import org.junit.runner.RunWith; |
| 28 | +import org.powermock.core.classloader.annotations.PrepareForTest; |
| 29 | +import org.powermock.modules.junit4.PowerMockRunner; |
23 | 30 |
|
24 | 31 | import java.util.Locale; |
| 32 | +import java.util.concurrent.Callable; |
25 | 33 |
|
| 34 | +@RunWith(PowerMockRunner.class) |
| 35 | +@PrepareForTest(TmcCore.class) |
26 | 36 | public class SettingsTest { |
27 | 37 |
|
28 | 38 | private Settings settings; |
29 | 39 | private Organization testOrganization; |
30 | 40 | private CliContext context; |
31 | 41 | private TestIo io; |
| 42 | + private TmcCore core; |
32 | 43 |
|
33 | 44 | @Before |
34 | 45 | public void setUp() { |
35 | 46 | testOrganization = new Organization("test", "test", "hy", "test", false); |
36 | 47 | settings = new Settings("testuser", "testpassword", testOrganization); |
37 | | - TmcCore core = new TmcCore(settings, new TaskExecutorImpl()); |
| 48 | + core = spy(new TmcCore(settings, new TaskExecutorImpl())); |
38 | 49 | SpywareSettings analyticsSettings = settings; |
39 | 50 | EventSendBuffer eventSendBuffer = new EventSendBuffer(analyticsSettings, new EventStore()); |
40 | 51 | AnalyticsFacade analyticsFacade = new AnalyticsFacade(analyticsSettings, eventSendBuffer); |
@@ -78,11 +89,20 @@ public void userDataExistsIfUsernameAndPasswordAreSet() { |
78 | 89 |
|
79 | 90 | @Test |
80 | 91 | public void ifPasswordExistsSettingsAreMigrated() { |
| 92 | + doReturn(new Callable<Void>() { |
| 93 | + @Override |
| 94 | + public Void call() throws Exception { |
| 95 | + return null; |
| 96 | + } |
| 97 | + }).when(core).authenticate(any(ProgressObserver.class), any(String.class)); |
81 | 98 | Account account = new Account("username", "password", testOrganization); |
82 | 99 | TmcSettingsHolder.set(settings); |
| 100 | + io.addLinePrompt(testOrganization.getSlug()); |
| 101 | + io.addLinePrompt("y"); |
| 102 | + io.addLinePrompt("y"); |
83 | 103 | settings.setAccount(this.context, account); |
84 | 104 | assertTrue(!settings.getPassword().isPresent()); |
85 | | - assertTrue(settings.getServerAddress().equals("https://tmc.mooc.fi/")); |
| 105 | + assertTrue(settings.getServerAddress().equals("https://tmc.mooc.fi")); |
86 | 106 | } |
87 | 107 |
|
88 | 108 | @Test |
|
0 commit comments