@Test public void testExpectedMapTypeOnRecord() throws Exception { String columnNames = "mapCol"; String columnTypes = "int"; ArrayWritable hiveRecord = createGroup(createInt(1)); String fileSchema = "message hive_schema {\n" + " optional group mapCol (MAP) {\n" + " repeated group map (MAP_KEY_VALUE) {\n" + " required binary key;\n" + " optional int32 value;\n" + " }\n" + " }\n" + "}\n"; try { writeParquetRecord(fileSchema, getParquetWritable(columnNames, columnTypes, hiveRecord)); fail(); } catch (RuntimeException e) { assertEquals( "Parquet record is malformed: Invalid data type: expected MAP type, but found: PRIMITIVE", e.getMessage()); } }
@Test public void testExpectedArrayTypeOnRecord() throws Exception { String columnNames = "arrayCol"; String columnTypes = "int"; ArrayWritable hiveRecord = createGroup(createInt(1)); String fileSchema = "message hive_schema {\n" + " optional group arrayCol (LIST) {\n" + " repeated group bag {\n" + " optional int32 array_element;\n" + " }\n" + " }\n" + "}\n"; try { writeParquetRecord(fileSchema, getParquetWritable(columnNames, columnTypes, hiveRecord)); fail(); } catch (RuntimeException e) { assertEquals( "Parquet record is malformed: Invalid data type: expected LIST type, but found: PRIMITIVE", e.getMessage()); } }
@Test public void testInterruptTerminalEventAwaitTimed() { TestSubscriber<Integer> ts = TestSubscriber.create(); final Thread t0 = Thread.currentThread(); Worker w = Schedulers.computation().createWorker(); try { w.schedule( new Action0() { @Override public void call() { t0.interrupt(); } }, 200, TimeUnit.MILLISECONDS); try { ts.awaitTerminalEvent(5, TimeUnit.SECONDS); fail("Did not interrupt wait!"); } catch (RuntimeException ex) { if (!(ex.getCause() instanceof InterruptedException)) { fail("The cause is not InterruptedException! " + ex.getCause()); } } } finally { w.unsubscribe(); } }
@Test(expected = NullPointerException.class) public void testInvokingTimerWithNullMethodName() throws Throwable { try { helper.invokeTimerFor(TestAggregator.class, null); } catch (RuntimeException e) { assertThat(e.getClass().getName(), is(RuntimeException.class.getName())); throw e.getCause(); } }
@Test(expected = NullPointerException.class) public void testInvokingNotExistentTimer() throws Throwable { try { helper.invokeTimerFor(TestAggregator.class, "blkjhsdgfksdyufgks"); } catch (RuntimeException e) { assertThat(e.getClass().getName(), is(RuntimeException.class.getName())); throw e.getCause(); } }
@Test public void shouldThrowExceptionWhenPollerForMaterialNotFound() { try { materialService.latestModification(mock(Material.class), null, null); fail("Should have thrown up"); } catch (RuntimeException e) { assertThat(e.getMessage(), is("unknown material type null")); } }
@Test public void throwExceptionIfChannelIsNull() throws Exception { when(connection.createChannel()).thenReturn(null); try { createRMQSink(); } catch (RuntimeException ex) { assertEquals("None of RabbitMQ channels are available", ex.getMessage()); } }
@Test public void getMembersWhenNoExecutionContext() throws Exception { Execution execution = this.componentManager.registerMockComponent(Execution.class); DocumentReference userReference = new DocumentReference("userwiki", "XWiki", "userpage"); try { new ReferenceUserIterator(userReference, null, execution).next(); } catch (RuntimeException expected) { assertEquals( "Aborting member extraction from passed references [[userwiki:XWiki.userpage]] since no " + "XWiki Context was found", expected.getMessage()); } }
@Test public void shouldReThrowWebServerException() throws IOException, InterruptedException { WebDaemon webDaemon = spy(new WebDaemon()); ReflectionUtils.setField(main, "webDaemon", webDaemon); InterruptedException toBeThrown = new InterruptedException("Ouch!"); doThrow(toBeThrown).when(webDaemon).start(any(ConfigurationForServer.class)); try { main.runMain(new String[] {"-ws", "--port=1234"}); fail("Should have thrown exception"); } catch (RuntimeException rte) { assertThat((InterruptedException) rte.getCause(), sameInstance(toBeThrown)); } }
@Test public void getMembersWhenSingleUserButDocumentFailsToLoad() throws Exception { setUpBaseMocks(); DocumentReference userReference = new DocumentReference("userwiki", "XWiki", "userpage"); when(xwiki.getDocument(userReference, this.xwikiContext)).thenThrow(new XWikiException()); Iterator<DocumentReference> iterator = new ReferenceUserIterator(userReference, null, this.execution); try { iterator.next(); } catch (RuntimeException expected) { assertEquals( "Failed to get document for User or Group [userwiki:XWiki.userpage] when extracting all " + "users for the references [[userwiki:XWiki.userpage]]", expected.getMessage()); } }
/** Put your functionality here if there IS a return object */ public Object getQuery(Stanza stanza, Object messageBean) { SuggestedCommunityAnalyserBean scaBean = (SuggestedCommunityAnalyserBean) messageBean; try { IIdentity returnIdentity = identityManager.fromJid("XCManager.societies.local"); } catch (InvalidFormatException e) { } switch (scaBean.getMethod()) { case processCSMRecommendations: try { // IIdentity owner = identityManager.fromJid(scaBean..getIdentity()); // String serviceType = scaBean.getServiceType(); processRelevanceRecommendations(); break; } catch (RuntimeException e) { e.printStackTrace(); } } return null; }
@Test public void throw_runtime_exception() throws Exception { try { final String data = "person"; final String help = null; final String nnew = null; final String diff = null; final String redirect = null; final String source = "test"; final String contentType = "UTF-8"; doThrow(new RuntimeException("some message", new IllegalStateException("some message"))) .when(messageHandler) .handle(any(UpdateRequest.class), any(UpdateContext.class)); subject.doGet(request, source, data, help, nnew, diff, redirect, contentType); fail(); } catch (RuntimeException e) { assertThat(e.getMessage(), is("some message")); } }