未验证 提交 36975eac 编写于 作者: P Phodal Huang

docs: add some test smell

上级 120ed6f2
......@@ -65,4 +65,5 @@ api.svg
!docs/sample/api.svg
coca_reporter
*.coverprofile
bug
\ No newline at end of file
bug
_fixtures/tbs/tbs
\ No newline at end of file
......@@ -473,6 +473,8 @@ Arch based on [Tequila](https://github.com/newlee/tequila)
Git Analysis inspired by [Code Maat](https://github.com/adamtornhill/code-maat)
Test bad smells inspired by [Test Smell Examples](https://testsmells.github.io/pages/testsmellexamples.html)
[![Phodal's Idea](http://brand.phodal.com/shields/idea-small.svg)](http://ideas.phodal.com/)
@ 2019 A [Phodal Huang](https://www.phodal.com)'s [Idea](http://github.com/phodal/ideas). This code is distributed under the MPL license. See `LICENSE` in this directory.
package tbs;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
public class AssertionRoulette {
@Test
public void testCloneNonBareRepoFromLocalTestServer() throws Exception {
Calculate calculate = new Calculate();
int result = calculate.add(7, 8);
int success = 15;
assertEquals(success, result);
int subResult = calculate.sub(9, 2);
int subSuccess = 7;
assertEquals(subSuccess, subResult);
}
}
package tbs;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ConditionalTest {
@Test
public void byGod() {
Calculate calculate = new Calculate();
// just examples
if (calculate.add(7, 9) == 16) {
if (calculate.sub(12, 9) == 3) {
int subSuccess = 7;
assertEquals(subSuccess, calculate.sub(9, 2));
}
}
}
}
package tbs;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ConstructorInitialization {
@Before
public void init() throws Exception {
}
@Test
public void name() {
Calculate calculate = new Calculate();
int result = calculate.add(7, 8);
int success = 15;
assertEquals(success, result);
}
}
package tbs;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class DuplicateAssert {
@Test
public void testXmlSanitizer() {
boolean valid = XmlSanitizer.isValid("Fritzbox");
assertEquals("Fritzbox is valid", true, valid);
valid = XmlSanitizer.isValid("Fritz Box");
assertEquals("Spaces are valid", true, valid);
valid = XmlSanitizer.isValid("Frützbüx");
assertEquals("Frützbüx is invalid", false, valid);
valid = XmlSanitizer.isValid("Fritz!box");
assertEquals("Exclamation mark is valid", true, valid);
}
}
package tbs;
import org.junit.Test;
public class EmptyTest {
@Test
public void testCredGetFullSampleV1() throws Throwable {
// ScrapedCredentials credentials = innerCredTest(FULL_SAMPLE_v1);
// assertEquals("p4ssw0rd", credentials.pass);
// assertEquals("user@example.com",credentials.user);
}
}
package tbs;
import org.junit.Ignore;
public class IgnoreTest {
@Ignore("Oops, Not Time fix it")
public void peerPriority() throws Exception {
}
}
package tbs;
import org.junit.Test;
import java.util.Calendar;
import static org.junit.Assert.assertEquals;
public class MagicNumberTest {
@Test
public void testGetLocalTimeAsCalendar() {
int result = 7 + 8;
assertEquals(15, result);
}
}
package tbs;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class MysteryGuest {
@Test
public void testPersistence() throws Exception {
try (FileOutputStream out = new FileOutputStream("people.bin");) {
int result = 5;
out.write(result);
} catch (FileNotFoundException e) {
// blabla
} catch (IOException e) {
// blabla
}
}
}
package tbs;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class RedundantAssertionTest {
@Test
public void testTrue() {
assertEquals(true, true);
}
}
package tbs;
import org.junit.Test;
public class RedundantPrint {
@Test
public void testTransform10mNEUAndBack() {
String result = "a, b, c";
System.out.println("result = " + result);
}
}
package tbs;
import org.junit.Test;
public class SleepyTest {
@Test
public void testEdictExternSearch() throws Exception {
Thread.sleep(500);
}
}
package tbs;
import org.junit.Test;
public class UnknownTest {
@Test
public void hitGetPOICategoriesApi() throws Exception {
String a = "blabla";
String b = "blablac";
String c = a + b;
}
}
package tbs;
public class Calculate {
public int add(int i, int i1) {
return i + i1;
}
public int sub(int i, int i1) {
return i - i1;
}
}
package tbs;
import java.util.regex.Pattern;
/**
* Replaces critical characters in xml files
*/
public final class XmlSanitizer {
private static final Pattern PURE_ASCII_STRING = Pattern.compile("^\\p{ASCII}*$"); // "[^\\p{ASCII}]+"
/**
* Checks if string contains &, <, >, ", ', non-ascii characters or anything other than A-Z, 0-9
*
* @param test String to test
* @return true, if string only contains valid chars
*/
public static boolean isValid(final String test) {
// check we don't have xml chars in it
boolean result = !test.contains("&") && !test.contains("<") && !test.contains(">") && !test.contains("\"") && !test.contains("'");
// assure we only have ASCII chars
result = result && PURE_ASCII_STRING.matcher(test).matches();
// assure we really only A-Z and numbers in it
result = result && (test.replaceAll("[^a-zA-Z0-9-+.!_\\s]", "").length() == test.length());
return result;
}
private XmlSanitizer() {
}
}
package tbs;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
public class AssertionRoulette {
@Test
public void testCloneNonBareRepoFromLocalTestServer() throws Exception {
Calculate calculate = new Calculate();
int result = calculate.add(7, 8);
int success = 15;
assertEquals(success, result);
int subResult = calculate.sub(9, 2);
int subSuccess = 7;
assertEquals(subSuccess, subResult);
}
}
package tbs;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ConditionalTest {
@Test
public void byGod() {
Calculate calculate = new Calculate();
// just examples
if (calculate.add(7, 9) == 16) {
if (calculate.sub(12, 9) == 3) {
int subSuccess = 7;
assertEquals(subSuccess, calculate.sub(9, 2));
}
}
}
}
package tbs;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ConstructorInitialization {
@Before
public void init() throws Exception {
}
@Test
public void name() {
Calculate calculate = new Calculate();
int result = calculate.add(7, 8);
int success = 15;
assertEquals(success, result);
}
}
package tbs;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class DuplicateAssert {
@Test
public void testXmlSanitizer() {
boolean valid = XmlSanitizer.isValid("Fritzbox");
assertEquals("Fritzbox is valid", true, valid);
valid = XmlSanitizer.isValid("Fritz Box");
assertEquals("Spaces are valid", true, valid);
valid = XmlSanitizer.isValid("Frützbüx");
assertEquals("Frützbüx is invalid", false, valid);
valid = XmlSanitizer.isValid("Fritz!box");
assertEquals("Exclamation mark is valid", true, valid);
}
}
package tbs;
import org.junit.Test;
public class EmptyTest {
@Test
public void testCredGetFullSampleV1() throws Throwable {
// ScrapedCredentials credentials = innerCredTest(FULL_SAMPLE_v1);
// assertEquals("p4ssw0rd", credentials.pass);
// assertEquals("user@example.com",credentials.user);
}
}
package tbs;
import org.junit.Ignore;
public class IgnoreTest {
@Ignore("Oops, Not Time fix it")
public void peerPriority() throws Exception {
}
}
package tbs;
import org.junit.Test;
import java.util.Calendar;
import static org.junit.Assert.assertEquals;
public class MagicNumberTest {
@Test
public void testGetLocalTimeAsCalendar() {
int result = 7 + 8;
assertEquals(15, result);
}
}
package tbs;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class MysteryGuest {
@Test
public void testPersistence() throws Exception {
try (FileOutputStream out = new FileOutputStream("people.bin");) {
int result = 5;
out.write(result);
} catch (FileNotFoundException e) {
// blabla
} catch (IOException e) {
// blabla
}
}
}
package tbs;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class RedundantAssertionTest {
@Test
public void testTrue() {
assertEquals(true, true);
}
}
package tbs;
import org.junit.Test;
public class RedundantPrint {
@Test
public void testTransform10mNEUAndBack() {
String result = "a, b, c";
System.out.println("result = " + result);
}
}
package tbs;
import org.junit.Test;
public class SleepyTest {
@Test
public void testEdictExternSearch() throws Exception {
Thread.sleep(500);
}
}
package tbs;
import org.junit.Test;
public class UnknownTest {
@Test
public void hitGetPOICategoriesApi() throws Exception {
String a = "blabla";
String b = "blablac";
String c = a + b;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册