Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 442f735

Browse files
author
Irene
committed
Fix tests
1 parent b4cf25e commit 442f735

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/test/java/fi/helsinki/cs/tmc/cli/backend/SettingsTest.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertFalse;
55
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.*;
69

710
import fi.helsinki.cs.tmc.cli.Application;
811
import fi.helsinki.cs.tmc.cli.analytics.AnalyticsFacade;
@@ -13,28 +16,36 @@
1316
import fi.helsinki.cs.tmc.cli.io.WorkDir;
1417
import fi.helsinki.cs.tmc.core.TmcCore;
1518
import fi.helsinki.cs.tmc.core.domain.Organization;
19+
import fi.helsinki.cs.tmc.core.domain.ProgressObserver;
1620
import fi.helsinki.cs.tmc.core.holders.TmcSettingsHolder;
1721
import fi.helsinki.cs.tmc.langs.util.TaskExecutorImpl;
1822
import fi.helsinki.cs.tmc.spyware.EventSendBuffer;
1923
import fi.helsinki.cs.tmc.spyware.EventStore;
2024
import fi.helsinki.cs.tmc.spyware.SpywareSettings;
2125
import org.junit.Before;
2226
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;
2330

2431
import java.util.Locale;
32+
import java.util.concurrent.Callable;
2533

34+
@RunWith(PowerMockRunner.class)
35+
@PrepareForTest(TmcCore.class)
2636
public class SettingsTest {
2737

2838
private Settings settings;
2939
private Organization testOrganization;
3040
private CliContext context;
3141
private TestIo io;
42+
private TmcCore core;
3243

3344
@Before
3445
public void setUp() {
3546
testOrganization = new Organization("test", "test", "hy", "test", false);
3647
settings = new Settings("testuser", "testpassword", testOrganization);
37-
TmcCore core = new TmcCore(settings, new TaskExecutorImpl());
48+
core = spy(new TmcCore(settings, new TaskExecutorImpl()));
3849
SpywareSettings analyticsSettings = settings;
3950
EventSendBuffer eventSendBuffer = new EventSendBuffer(analyticsSettings, new EventStore());
4051
AnalyticsFacade analyticsFacade = new AnalyticsFacade(analyticsSettings, eventSendBuffer);
@@ -78,11 +89,20 @@ public void userDataExistsIfUsernameAndPasswordAreSet() {
7889

7990
@Test
8091
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));
8198
Account account = new Account("username", "password", testOrganization);
8299
TmcSettingsHolder.set(settings);
100+
io.addLinePrompt(testOrganization.getSlug());
101+
io.addLinePrompt("y");
102+
io.addLinePrompt("y");
83103
settings.setAccount(this.context, account);
84104
assertTrue(!settings.getPassword().isPresent());
85-
assertTrue(settings.getServerAddress().equals("https://tmc.mooc.fi/"));
105+
assertTrue(settings.getServerAddress().equals("https://tmc.mooc.fi"));
86106
}
87107

88108
@Test

src/test/java/fi/helsinki/cs/tmc/cli/command/HelpCommandTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
import static org.mockito.Mockito.mock;
44

55
import fi.helsinki.cs.tmc.cli.Application;
6+
import fi.helsinki.cs.tmc.cli.analytics.AnalyticsFacade;
67
import fi.helsinki.cs.tmc.cli.backend.Settings;
78
import fi.helsinki.cs.tmc.cli.core.CliContext;
89
import fi.helsinki.cs.tmc.cli.io.TestIo;
910
import fi.helsinki.cs.tmc.cli.io.WorkDir;
1011
import fi.helsinki.cs.tmc.core.TmcCore;
1112

13+
import fi.helsinki.cs.tmc.langs.util.TaskExecutor;
14+
import fi.helsinki.cs.tmc.langs.util.TaskExecutorImpl;
15+
import fi.helsinki.cs.tmc.spyware.EventSendBuffer;
16+
import fi.helsinki.cs.tmc.spyware.EventStore;
17+
import fi.helsinki.cs.tmc.spyware.SpywareSettings;
1218
import org.junit.Before;
1319
import org.junit.Test;
1420

@@ -20,7 +26,13 @@ public class HelpCommandTest {
2026
@Before
2127
public void setUp() {
2228
io = new TestIo();
23-
CliContext ctx = new CliContext(io, mock(TmcCore.class), new WorkDir(), new Settings(), null);
29+
Settings settings = new Settings();
30+
TaskExecutor tmcLangs = new TaskExecutorImpl();
31+
TmcCore core = new TmcCore(settings, tmcLangs);
32+
SpywareSettings analyticsSettings = new Settings();
33+
EventSendBuffer eventSendBuffer = new EventSendBuffer(analyticsSettings, new EventStore());
34+
AnalyticsFacade analyticsFacade = new AnalyticsFacade(analyticsSettings, eventSendBuffer);
35+
CliContext ctx = new CliContext(io, core, new WorkDir(), new Settings(), analyticsFacade);
2436
app = new Application(ctx);
2537
}
2638

0 commit comments

Comments
 (0)