private void mock() throws ParseException, ExpiredException, IOException, ProtocolException { ClientData.setUserData("Massbon", "Samu"); PowerMockito.mockStatic(ClientData.class); PowerMockito.when(ClientData.getCurrentCourse(Mockito.anyString())) .thenReturn(Optional.<Course>of(new Course())); PowerMockito.when(ClientData.getFormattedUserData()).thenReturn("Bossman:Samu"); }
@Test(expected = ProtocolException.class) public void throwsErrorIfCourseCantBeRetrieved() throws Exception { PowerMockito.when(ClientData.userDataExists()).thenReturn(true); PowerMockito.when(ClientData.getCurrentCourse(Mockito.anyString())) .thenReturn(Optional.<Course>absent()); paste.data.put("path", "asdsad"); paste.checkData(); }
/** Mocks CourseSubmitter and injects it into Paste command. */ @Before public void setup() throws Exception { Mailbox.create(); mock(); ClientData.setUserData("Bossman", "Samu"); ClientData.setProjectRootFinder(new ProjectRootFinderStub()); TmcServiceScheduler.disablePolling(); submitterMock = Mockito.mock(CourseSubmitter.class); when(submitterMock.submitPaste(Mockito.anyString())).thenReturn(pasteUrl); paste = new Paste(submitterMock); }
@Test public void submitReturnsBadOutputWhenCodeIsBad() throws Exception { PowerMockito.when(ClientData.userDataExists()).thenReturn(true); paste.setParameter("path", "/hieno/path"); String result = paste.parseData(paste.call()).get(); assertTrue(result.contains(pasteUrl)); }
@Test(expected = ProtocolException.class) public void throwsErrorIfNoCredentialsPresent() throws Exception { paste.data.put("path", "asdsad"); ClientData.clearUserData(); paste.checkData(); }
@Test(expected = ProtocolException.class) public void checkDataFailIfNoAuth() throws Exception { ClientData.clearUserData(); paste.checkData(); }
/** Check that data checking success. */ @Test public void testCheckDataSuccess() throws ProtocolException, IOException { PowerMockito.when(ClientData.userDataExists()).thenReturn(true); paste.setParameter("path", "/home/tmccli/uolevipuistossa"); paste.checkData(); }
@After public void clean() { ClientData.clearUserData(); }