From 7e3be2fcbbecc0e684dbcf84bb8a09eeffebc7f2 Mon Sep 17 00:00:00 2001 From: Ilia Kebets Date: Thu, 21 Nov 2024 08:46:18 +0100 Subject: [PATCH] add template for check test --- tools/resources/ruletest.template_java | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tools/resources/ruletest.template_java diff --git a/tools/resources/ruletest.template_java b/tools/resources/ruletest.template_java new file mode 100644 index 00000000000..df99a9c5ce4 --- /dev/null +++ b/tools/resources/ruletest.template_java @@ -0,0 +1,41 @@ +/* + * SonarQube JavaScript Plugin + * Copyright (C) 2011-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.javascript.checks; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.gson.Gson; +import org.junit.jupiter.api.Test; + +// TODO: delete this file if the rule is not configurable +class ___JAVA_RULE_CLASS_NAME___Test { + + @Test + void configurations() { + HardcodedCredentialsCheck check = new ___JAVA_RULE_CLASS_NAME___(); + // default configuration + String defaultConfigAsString = new Gson().toJson(check.configurations()); + assertThat(defaultConfigAsString).isEqualTo("[{\"foo\":\"42\"}]"); + + check.foo = "42"; + String customConfigAsString = new Gson().toJson(check.configurations()); + assertThat(customConfigAsString).isEqualTo("[{\"foo\":\"42\"}]"); + } +}