Skip to content

Commit 47d25b4

Browse files
committed
create utility files
1 parent 9360066 commit 47d25b4

File tree

14 files changed

+1152
-0
lines changed

14 files changed

+1152
-0
lines changed

pom.xml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.hackerrank</groupId>
6+
<artifactId>junit-ordered-test-runner</artifactId>
7+
<version>1.0</version>
8+
<packaging>jar</packaging>
9+
10+
<name>${project.groupId}:${project.artifactId}</name>
11+
<description>An application to provide support for executing tests in the specific order
12+
and generate the customized XML report.
13+
</description>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<maven.compiler.source>1.8</maven.compiler.source>
18+
<maven.compiler.target>1.8</maven.compiler.target>
19+
</properties>
20+
21+
<licenses>
22+
<license>
23+
<name>Apache License 2.0</name>
24+
<url>http://opensource.org/licenses/Apache-2.0</url>
25+
</license>
26+
</licenses>
27+
28+
<developers>
29+
<developer>
30+
<name>Abhimanyu Singh</name>
31+
<email>abhimanyusingh@hackerrank.com</email>
32+
<organization>HackerRank</organization>
33+
<organizationUrl>https://www.hackerrank.com/</organizationUrl>
34+
</developer>
35+
</developers>
36+
37+
<scm>
38+
<connection>scm:git:git://github.com/interviewstreet/junit-ordered-test-runner.git</connection>
39+
<developerConnection>scm:git:ssh://github.com:interviewstreet/junit-ordered-test-runner.git</developerConnection>
40+
<url>http://github.com/interviewstreet/junit-ordered-test-runner/tree/master</url>
41+
</scm>
42+
43+
<dependencies>
44+
<dependency>
45+
<groupId>junit</groupId>
46+
<artifactId>junit</artifactId>
47+
<version>4.12</version>
48+
<type>jar</type>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>com.fasterxml.jackson.core</groupId>
53+
<artifactId>jackson-databind</artifactId>
54+
<version>2.9.6</version>
55+
<type>jar</type>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>commons-lang</groupId>
60+
<artifactId>commons-lang</artifactId>
61+
<version>2.6</version>
62+
<type>jar</type>
63+
</dependency>
64+
65+
<dependency>
66+
<groupId>org.jdom</groupId>
67+
<artifactId>jdom</artifactId>
68+
<version>1.1</version>
69+
<type>jar</type>
70+
</dependency>
71+
</dependencies>
72+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2018 HackerRank.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.hackerrank.test.utility;
17+
18+
/**
19+
*
20+
* @author Abhimanyu Singh
21+
* @author abhimanyusingh@hackerrank.com
22+
* @version 1.0
23+
* @since 1.0
24+
*/
25+
public class Color {
26+
27+
public static final String RESET = "\033[0m";
28+
29+
public static final String BLACK = "\033[0;30m";
30+
public static final String RED = "\033[0;31m";
31+
public static final String GREEN = "\033[0;32m";
32+
public static final String YELLOW = "\033[0;33m";
33+
public static final String BLUE = "\033[0;34m";
34+
public static final String WHITE = "\033[0;37m";
35+
36+
public static final String BLACK_BOLD = "\033[1;30m";
37+
public static final String RED_BOLD = "\033[1;31m";
38+
public static final String GREEN_BOLD = "\033[1;32m";
39+
public static final String YELLOW_BOLD = "\033[1;33m";
40+
public static final String BLUE_BOLD = "\033[1;34m";
41+
public static final String WHITE_BOLD = "\033[1;37m";
42+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2018 HackerRank.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.hackerrank.test.utility;
17+
18+
import java.math.BigDecimal;
19+
20+
/**
21+
*
22+
* @author Abhimanyu Singh
23+
* @author abhimanyusingh@hackerrank.com
24+
* @version 1.0
25+
* @since 1.0
26+
*/
27+
public class NumberFormatter {
28+
29+
/**
30+
*
31+
* @param value double value
32+
* @param precision number of decimal places
33+
* @return string representation of rounded double to fixed decimal places
34+
*/
35+
public static String stringValue(double value, int precision) {
36+
return new BigDecimal(value)
37+
.setScale(precision, BigDecimal.ROUND_HALF_EVEN)
38+
.toString();
39+
}
40+
41+
/**
42+
*
43+
* @param value double value
44+
* @param precision number of decimal places
45+
* @return rounded double to fixed decimal places
46+
*/
47+
public static double doubleValue(double value, int precision) {
48+
return new BigDecimal(value)
49+
.setScale(precision, BigDecimal.ROUND_HALF_EVEN)
50+
.doubleValue();
51+
}
52+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2018 HackerRank.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.hackerrank.test.utility;
17+
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
/**
24+
*
25+
* @author Abhimanyu Singh
26+
* @author abhimanyusingh@hackerrank.com
27+
* @version 1.0
28+
* @since 1.0
29+
*/
30+
@Retention(RetentionPolicy.RUNTIME)
31+
@Target({
32+
ElementType.METHOD
33+
})
34+
public @interface Order {
35+
36+
/**
37+
*
38+
* @return order
39+
*/
40+
public int value();
41+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2018 HackerRank.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.hackerrank.test.utility;
17+
18+
import java.util.HashMap;
19+
import java.util.List;
20+
import java.util.Map;
21+
import static java.util.stream.Collectors.toList;
22+
import org.junit.runners.BlockJUnit4ClassRunner;
23+
import org.junit.runners.model.FrameworkMethod;
24+
import org.junit.runners.model.InitializationError;
25+
26+
/**
27+
*
28+
* @author Abhimanyu Singh
29+
* @author abhimanyusingh@hackerrank.com
30+
* @version 1.0
31+
* @since 1.0
32+
*/
33+
public class OrderedTestRunner extends BlockJUnit4ClassRunner {
34+
35+
/**
36+
*
37+
* @param clazz test class
38+
* @throws InitializationError initialization error
39+
*/
40+
public OrderedTestRunner(Class<?> clazz) throws InitializationError {
41+
super(clazz);
42+
}
43+
44+
/**
45+
*
46+
* @return test methods ordered by execution order
47+
*/
48+
@Override
49+
protected List<FrameworkMethod> computeTestMethods() {
50+
Map<FrameworkMethod, Integer> orders = new HashMap();
51+
52+
List<FrameworkMethod> methods = super.computeTestMethods();
53+
54+
int maxOrder = 0;
55+
56+
for (FrameworkMethod method : methods) {
57+
Order order = method.getAnnotation(Order.class);
58+
maxOrder = Math.max(maxOrder, order == null ? 0 : order.value());
59+
60+
orders.put(method, order == null ? null : order.value());
61+
}
62+
63+
final int order = maxOrder + 1;
64+
65+
methods.forEach(method -> orders.computeIfAbsent(method, value -> order));
66+
67+
return methods.stream()
68+
.sorted((f1, f2) -> orders.get(f1) - orders.get(f2))
69+
.collect(toList());
70+
}
71+
}

0 commit comments

Comments
 (0)