@Test public void format_date_time() { TimeZone initialTz = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT+1")); assertThat(underTest.formatDateTime(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22T19:10:03+0100"))).startsWith("Jan 22, 2014"); TimeZone.setDefault(initialTz); }
@Test public void dotWorkingDir() throws IOException { File sonarHome = temp.getRoot(); String globalWorkDir = "."; ScannerProperties globalProperties = new ScannerProperties(ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath(), CoreProperties.GLOBAL_WORKING_DIRECTORY, globalWorkDir)); TempFolder tempFolder = tempFolderProvider.provide(globalProperties); File newFile = tempFolder.newFile(); assertThat(newFile.getParentFile().getParentFile().getAbsolutePath()).isEqualTo(sonarHome.getAbsolutePath()); assertThat(newFile.getParentFile().getName()).startsWith(".sonartmp_"); }
@Test public void shouldFormatDateTime_with_long() { assertThat(DateUtils.formatDateTime(System.currentTimeMillis())).startsWith("20"); assertThat(DateUtils.formatDateTime(System.currentTimeMillis()).length()).isGreaterThan(20); }
@Test public void loadPropsFromCommandLineArgs_missing_argument() { try { ConfigurationUtils.loadPropsFromCommandLineArgs(new String[0]); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).startsWith("Only a single command-line argument is accepted"); } }
@Test public void shouldFormatDate() { assertThat(DateUtils.formatDate(new Date())).startsWith("20"); assertThat(DateUtils.formatDate(new Date())).hasSize(10); }
@Test public void format_date_time_null_safe() { assertThat(DateUtils.formatDateTimeNullSafe(new Date())).startsWith("20"); assertThat(DateUtils.formatDateTimeNullSafe(new Date()).length()).isGreaterThan(20); assertThat(DateUtils.formatDateTimeNullSafe(null)).isEmpty(); }
private void checkSvg(TestResponse response, String expectedLabel, String expectedValue, Color expectedColorValue) { assertThat(response.getHeader("ETag")).startsWith("W/"); assertThat(response.getHeader("Cache-Control")).contains("no-cache"); assertThat(response.getHeader("Expires")).isNull(); assertThat(response.getInput()).contains( "<text", expectedLabel + "</text>", "<text", expectedValue + "</text>", "rect fill=\"" + expectedColorValue.getValue() + "\""); }
@Test public void start_publishes_URL_in_IPC() { try (DefaultProcessCommands commands = DefaultProcessCommands.secondary(this.sharedDir, 1)) { assertThat(commands.getHttpUrl()).startsWith("http://127.0.0.1:"); } }
@Test public void testWithOneLongOption() throws CLIException { Option[] options = new Option[]{ new Option().setShortName("f").setLongName("file").setSingleValued(true) }; cli.addOptions(Arrays.asList(options)); CommandLine evaluated = cli.parse(Collections.singletonList("--file=hello.txt")); assertThat(evaluated.cli().getOptions()).hasSize(1); assertThat((String) evaluated.getOptionValue("file")).isEqualTo("hello.txt"); assertThat(evaluated.getOptionValues("f")).containsExactly("hello.txt"); StringBuilder usage = new StringBuilder(); cli.usage(usage); assertThat(usage.toString()).startsWith("Usage: test [-f <value>]"); assertThat(usage.toString()).contains("-f,--file <value>"); }
@Test public void get_index() throws Exception { writeStringToFile(new File(batchDir, "sonar-batch.jar"), "something"); batchIndex.start(); String index = tester.newRequest().execute().getInput(); assertThat(index).startsWith("sonar-batch.jar|"); }
private static void assertEqual(QProfileDto p1, QProfileDto p2) { assertThat(p2.getOrganizationUuid()).isEqualTo(p1.getOrganizationUuid()); assertThat(p2.getName()).isEqualTo(p1.getName()); assertThat(p2.getKee()).startsWith(p1.getKee()); assertThat(p2.getLanguage()).isEqualTo(p1.getLanguage()); assertThat(p2.getId()).isEqualTo(p1.getId()); assertThat(p2.getParentKee()).isEqualTo(p1.getParentKee()); }
@Test public void build_adds_AUTO_INCREMENT_clause_on_MySql() { List<String> stmts = new CreateTableBuilder(MY_SQL, TABLE_NAME) .addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT) .build(); assertThat(stmts).hasSize(1); assertThat(stmts.iterator().next()) .startsWith("CREATE TABLE table_42 (id INTEGER NOT NULL AUTO_INCREMENT, CONSTRAINT pk_table_42 PRIMARY KEY (id))"); }
@Test public void stopInfo_adds_context_after_time_by_default() { addSomeContext(underTest); underTest.start().stopInfo("Rules registered"); assertThat(tester.logs()).hasSize(1); assertThat(tester.logs(LoggerLevel.INFO).get(0)) .startsWith("Rules registered | time=") .endsWith("ms | a_string=bar | an_int=42 | after_start=true"); }
@Test public void testWithOneLongOptionUsingSpace() throws CLIException { Option[] options = new Option[]{ new Option().setShortName("f").setLongName("file") .setSingleValued(true) }; cli.addOptions(Arrays.asList(options)); CommandLine evaluated = cli.parse(Arrays.asList("--file", "hello.txt")); assertThat(evaluated.cli().getOptions()).hasSize(1); assertThat((String) evaluated.getOptionValue("file")).isEqualTo("hello.txt"); assertThat(evaluated.getOptionValues("f")).containsExactly("hello.txt"); StringBuilder usage = new StringBuilder(); cli.usage(usage); assertThat(usage.toString()).startsWith("Usage: test [-f <value>]"); }
@Test public void stopError_adds_context_before_time_if_logTimeLast_is_true() { addSomeContext(underTest); underTest.logTimeLast(true); underTest.start().stopError("Rules registered"); assertThat(tester.logs()).hasSize(1); assertThat(tester.logs(LoggerLevel.ERROR).get(0)) .startsWith("Rules registered | a_string=bar | an_int=42 | after_start=true | time=") .endsWith("ms"); }
@Test public void stopInfo_adds_context_before_time_if_logTimeLast_is_true() { addSomeContext(underTest); underTest.logTimeLast(true); underTest.start().stopInfo("Rules registered"); assertThat(tester.logs()).hasSize(1); assertThat(tester.logs(LoggerLevel.INFO).get(0)) .startsWith("Rules registered | a_string=bar | an_int=42 | after_start=true | time=") .endsWith("ms"); }
@Test public void stopTrace_adds_context_after_time_by_default() { tester.setLevel(LoggerLevel.TRACE); addSomeContext(underTest); underTest.start().stopTrace("Rules registered"); assertThat(tester.logs()).hasSize(1); assertThat(tester.logs(LoggerLevel.TRACE).get(0)) .startsWith("Rules registered | time=") .endsWith("ms | a_string=bar | an_int=42 | after_start=true"); }
@Test public void stopTrace_adds_context_before_time_if_logTimeLast_is_true() { tester.setLevel(LoggerLevel.TRACE); addSomeContext(underTest); underTest.logTimeLast(true); underTest.start().stopTrace("Rules registered"); assertThat(tester.logs()).hasSize(1); assertThat(tester.logs(LoggerLevel.TRACE).get(0)) .startsWith("Rules registered | a_string=bar | an_int=42 | after_start=true | time=") .endsWith("ms"); }
@Test public void write_json_by_default() { TestRequest request = new TestRequest(); DumbResponse response = new DumbResponse(); Issues.Issue msg = Issues.Issue.newBuilder().setKey("I1").build(); WsUtils.writeProtobuf(msg, request, response); assertThat(response.stream().mediaType()).isEqualTo(MediaTypes.JSON); assertThat(response.outputAsString()) .startsWith("{") .contains("\"key\":\"I1\"") .endsWith("}"); }
@Test public void create_user_generates_unique_login_no_login_provided() { createDefaultGroup(); UserDto user = underTest.createAndCommit(db.getSession(), NewUser.builder() .setName("John Doe") .build(), u -> { }); UserDto dto = dbClient.userDao().selectByLogin(session, user.getLogin()); assertThat(dto.getLogin()).startsWith("john-doe"); assertThat(dto.getName()).isEqualTo("John Doe"); }