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

Commit 80855f4

Browse files
authored
Merge pull request #337 from tmc-cli/feedback-tests-jclc
Feedback tests jclc
2 parents ea97a4c + cb95a1b commit 80855f4

2 files changed

Lines changed: 81 additions & 4 deletions

File tree

src/test/java/fi/helsinki/cs/tmc/cli/io/TestIo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,22 @@ public void print(String str) {
8989
@Override
9090
public String readLine(String prompt) {
9191
usePrompt(PromptType.TEXT_PROMPT);
92+
this.printedText.append(prompt + "\n");
9293
return textPrompts.pop();
9394
}
9495

9596
@Override
9697
public String readPassword(String prompt) {
9798
usePrompt(PromptType.PASSWORD_PROMPT);
99+
this.printedText.append(prompt + "\n");
98100
return passwordPrompts.pop();
99101
}
100102

101103
@Override
102104
public boolean readConfirmation(String prompt, boolean defaultToYes) {
103105
usePrompt(PromptType.CONFIRM_PROMPT);
106+
String yesNo = (defaultToYes) ? " [Y/n] " : " [y/N] ";
107+
this.printedText.append(prompt + yesNo);
104108
return (boolean) confirmationPrompts.pop();
105109
}
106110

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,92 @@
11
package fi.helsinki.cs.tmc.cli.tmcstuff;
22

3+
import static com.google.common.truth.Truth.assertThat;
4+
import static org.mockito.Matchers.any;
5+
import static org.mockito.Matchers.anyBoolean;
6+
import static org.mockito.Matchers.anyString;
7+
import static org.mockito.Mockito.mock;
8+
import static org.powermock.api.mockito.PowerMockito.mockStatic;
9+
import static org.powermock.api.mockito.PowerMockito.verifyStatic;
10+
import static org.powermock.api.mockito.PowerMockito.when;
11+
12+
import fi.helsinki.cs.tmc.cli.CliContext;
313
import fi.helsinki.cs.tmc.cli.io.ExternalsUtil;
14+
import fi.helsinki.cs.tmc.cli.io.TestIo;
15+
import fi.helsinki.cs.tmc.core.domain.submission.FeedbackAnswer;
16+
import fi.helsinki.cs.tmc.core.domain.submission.FeedbackQuestion;
417

5-
import org.junit.Ignore;
18+
import org.junit.Before;
619
import org.junit.Test;
720
import org.junit.runner.RunWith;
21+
import org.mockito.ArgumentCaptor;
22+
import org.mockito.Captor;
23+
import org.mockito.Mockito;
24+
import org.powermock.api.mockito.PowerMockito;
825
import org.powermock.core.classloader.annotations.PrepareForTest;
926
import org.powermock.modules.junit4.PowerMockRunner;
1027

28+
import java.net.URI;
29+
import java.util.Arrays;
30+
import java.util.List;
31+
1132
@RunWith(PowerMockRunner.class)
12-
@PrepareForTest(ExternalsUtil.class)
33+
@PrepareForTest({ExternalsUtil.class, TmcUtil.class})
1334
public class FeedbackHandlerTest {
35+
private List<FeedbackQuestion> questions;
36+
private String a1;
37+
private String a2;
38+
private String a3;
39+
private TestIo io;
40+
private CliContext ctx;
41+
@Captor ArgumentCaptor<List<FeedbackAnswer>> answerCaptor;
42+
43+
@Before
44+
public void setup() {
45+
a1 = a2 = a3 = "";
46+
mockStatic(ExternalsUtil.class);
47+
mockStatic(TmcUtil.class);
48+
when(ExternalsUtil.getUserEditedMessage(anyString(), anyString(), anyBoolean()))
49+
.thenReturn("you're programm sucks");
50+
FeedbackQuestion q1 = new FeedbackQuestion();
51+
q1.setQuestion("What's your opinion on TMC-CLI?");
52+
q1.setKind("text");
53+
FeedbackQuestion q2 = new FeedbackQuestion();
54+
q2.setQuestion("Please rate this program.");
55+
q2.setKind("intrange\\[0\\.\\.4]");
56+
FeedbackQuestion q3 = new FeedbackQuestion();
57+
q3.setQuestion("This type of question doesn't really exist but whatever");
58+
q3.setKind("misc");
59+
questions = Arrays.asList(q1, q2, q3);
60+
io = new TestIo();
61+
ctx = mock(CliContext.class);
62+
Mockito.when(ctx.getIo()).thenReturn(io);
63+
}
1464

15-
@Ignore
1665
@Test
17-
public void todo() {
66+
public void sendingFeedbackWorks() {
67+
PowerMockito.when(
68+
TmcUtil.sendFeedback(any(CliContext.class), any(List.class), any(URI.class)))
69+
.thenReturn(true);
70+
io.addLinePrompt("1");
71+
io.addLinePrompt("who cars");
72+
io.addConfirmationPrompt(true);
73+
FeedbackHandler handler = new FeedbackHandler(ctx);
74+
handler.sendFeedback(questions, URI.create("https://eeeeeeeeeee.com"));
75+
76+
verifyStatic();
77+
TmcUtil.sendFeedback(any(CliContext.class), answerCaptor.capture(), any(URI.class));
78+
List<FeedbackAnswer> answers = answerCaptor.getValue();
79+
assertThat(answers.get(0).getQuestion().getQuestion()).isEqualTo(
80+
"What's your opinion on TMC-CLI?");
81+
assertThat(answers.get(0).getAnswer()).isEqualTo("you're programm sucks");
82+
io.assertContains("Please rate this program.");
83+
assertThat(answers.get(1).getQuestion().getQuestion()).isEqualTo(
84+
"Please rate this program.");
85+
assertThat(answers.get(1).getAnswer()).isEqualTo("1");
86+
io.assertContains(
87+
"Feedback question: This type of question doesn't really exist but whatever");
88+
assertThat(answers.get(2).getQuestion().getQuestion()).isEqualTo(
89+
"This type of question doesn't really exist but whatever");
90+
assertThat(answers.get(2).getAnswer()).isEqualTo("who cars");
1891
}
1992
}

0 commit comments

Comments
 (0)