Refine search
private void expectGetValueFailureWithISE(Runnable runnable) { try { runnable.run(); fail("An IllegalStateException should have been raised"); } catch (IllegalStateException e) { assertThat(e).hasMessage("Param has no value. Use isPresent() before calling getValue()"); } }
@Test public void testNoArgConstructorDoesntExist() { Class<RunAsUserToken> clazz = RunAsUserToken.class; try { clazz.getDeclaredConstructor((Class[]) null); fail("Should have thrown NoSuchMethodException"); } catch (NoSuchMethodException expected) { assertThat(true).isTrue(); } }
@Test public void setOriginalFile_throws_IAE_when_type_is_no_FILE() { for (Component component : COMPONENTS_EXCEPT_FILE) { try { underTest.setOriginalFile(component, SOME_ORIGINAL_FILE); fail("should have raised a NPE"); } catch (IllegalArgumentException e) { assertThat(e) .isInstanceOf(IllegalArgumentException.class) .hasMessage("file must be of type FILE"); } } }
private void expectSupplierCanNotBeNullNPE(Runnable runnable) { try { runnable.run(); fail("A NullPointerException should have been raised"); } catch (NullPointerException e) { assertThat(e).hasMessage("default value supplier can't be null"); } }
@Test public void testMissingArgWithBursting() throws Exception { String[] args = new String[]{"-acb"}; try { CommandLine evaluated = cli.parse(Arrays.asList(args)); fail("exception expected"); } catch (MissingValueException e) { assertThat(e.getOption().getShortName()).isEqualTo("b"); } }
@Override public void consume(int lineIdx, @Nullable byte[] hash) { switch (lineIdx) { case 1: assertThat(hash).isNull(); break; default: fail("Invalid line"); } } });
@Test public void base64UrlSafeEncode() { String input = "haha,i am a very long message"; String result = EncodeUtil.encodeBase64UrlSafe(input.getBytes()); assertThat(new String(EncodeUtil.decodeBase64UrlSafe(result), Charsets.UTF_8)).isEqualTo(input); try { assertThat(result).isEqualTo(EncodeUtil.decodeBase64UrlSafe("AQIPE+8=")); fail("should throw exception before"); } catch (Throwable t) { assertThat(t).isInstanceOf(IllegalArgumentException.class); } } }
private static void failsWithNPEForNullQualifiers(Consumer<PropertyDefinition.Builder> consumer) { PropertyDefinition.Builder builder = PropertyDefinition.builder(randomAlphabetic(3)); NOT_ALLOWED_QUALIFIERS.forEach(qualifier -> { try { consumer.accept(builder); fail("A NullPointerException should have been thrown for null qualifier"); } catch (NullPointerException e) { assertThat(e).hasMessage("Qualifier cannot be null"); } }); }
@Test public void testRejectsEmptyProvidersList() { AfterInvocationProviderManager manager = new AfterInvocationProviderManager(); List list = new Vector(); try { manager.setProviders(list); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException expected) { assertThat(true).isTrue(); } }
private static void failsWithIAEForUnsupportedQualifiers(BiConsumer<PropertyDefinition.Builder, String> biConsumer) { PropertyDefinition.Builder builder = PropertyDefinition.builder(randomAlphabetic(3)); NOT_ALLOWED_QUALIFIERS.forEach(qualifier -> { try { biConsumer.accept(builder, qualifier); fail("A IllegalArgumentException should have been thrown for qualifier " + qualifier); } catch (IllegalArgumentException e) { assertThat(e).hasMessage("Qualifier must be one of [TRK, VW, BRC, SVW, APP]"); } }); }
@Test public void failWhenCallingTask() throws Exception { try { tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .put("sonar.task", "fake").build()) .execute(); fail("Expected exception"); } catch (Exception e) { assertThat(e).isInstanceOf(MessageException.class).hasMessage("Tasks support was removed in SonarQube 7.6."); } }
private void createThrowsExceptionThrownByOrganizationValidation(UserDto user) throws OrganizationUpdater.KeyConflictException { try { underTest.create(dbSession, user, FULL_POPULATED_NEW_ORGANIZATION, EMPTY_ORGANIZATION_CONSUMER); fail(exceptionThrownByOrganizationValidation + " should have been thrown"); } catch (IllegalArgumentException e) { assertThat(e).isSameAs(exceptionThrownByOrganizationValidation); } }
@Test public void testRejectsNullProvidersList() throws Exception { AfterInvocationProviderManager manager = new AfterInvocationProviderManager(); try { manager.afterPropertiesSet(); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException expected) { assertThat(true).isTrue(); } }