Permalink
Browse files

Project import

  • Loading branch information...
1 parent 9c2beb5 commit 5b9759e458dab5a63949f5be206268f0a51c244c @linsolas committed Nov 25, 2011
View
23 foobarqix-maven-plugin/pom.xml
@@ -0,0 +1,23 @@
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>fr.linsolas.foobarqix</groupId>
+ <artifactId>foobarqix-maven-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <version>1.0</version>
+ <name>foobarqix-maven-plugin Maven Mojo</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
View
40 foobarqix-maven-plugin/src/main/java/fr/linsolas/FooBarQix.java
@@ -0,0 +1,40 @@
+package fr.linsolas;
+
+/**
+ * Utility class to calculate FooBarQix.
+ *
+ * @author Romain Linsolas
+ */
+public final class FooBarQix {
+
+ private static final String FOO = "Foo";
+
+ private static final String BAR = "Bar";
+
+ private static final String QIX = "Qix";
+
+ public static String getFooBarQix(int nb) {
+ String val = String.valueOf(nb);
+ StringBuffer sb = new StringBuffer();
+ sb.append(nb % 3 == 0 ? FOO : "");
+ sb.append(nb % 5 == 0 ? BAR : "");
+ sb.append(nb % 7 == 0 ? QIX : "");
+
+ for (char c : val.toCharArray()) {
+ switch (c) {
+ case '3':
+ sb.append(FOO);
+ break;
+ case '5':
+ sb.append(BAR);
+ break;
+ case '7':
+ sb.append(QIX);
+ break;
+ }
+ }
+ sb.append(sb.length() == 0 ? val : "");
+ return sb.toString();
+ }
+
+}
View
37 foobarqix-maven-plugin/src/main/java/fr/linsolas/FooBarQixMojo.java
@@ -0,0 +1,37 @@
+package fr.linsolas;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * Maven Plugin for FooBarQix.
+ *
+ * @goal foobarqix
+ *
+ * @phase process-sources
+ */
+public class FooBarQixMojo extends AbstractMojo {
+
+ /**
+ * Start of the counter.
+ *
+ * @parameter
+ * @required
+ */
+ private int from = 1;
+
+ /**
+ * End of the counter.
+ *
+ * @parameter
+ * @required
+ */
+ private int to = 100;
+
+ public void execute() throws MojoExecutionException {
+ for (int i = from; i <= to; i++) {
+ getLog().info("\t" + FooBarQix.getFooBarQix(i));
+ }
+ }
+
+}
View
61 foobarqix-maven-plugin/src/test/java/fr/linsolas/FooBarQixAllTest.java
@@ -0,0 +1,61 @@
+package fr.linsolas;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import fr.linsolas.FooBarQix;
+
+/**
+ * Test all values from 1 to 100 using Parameterized JUnit annotation.
+ *
+ * @author Romain Linsolas
+ */
+@RunWith(Parameterized.class)
+public class FooBarQixAllTest {
+
+ @Parameters
+ public static List<Object[]> getArray() {
+ List<Object[]> list = new ArrayList<Object[]>();
+ for (int i = 0; i < INDEX.length; i++) {
+ list.add(new Object[] { INDEX[i], RESULT[i] });
+ }
+ return list;
+ }
+
+ private static final int[] INDEX = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
+ 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
+ 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
+ 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100 };
+
+ private static final String[] RESULT = { "1", "2", "FooFoo", "4", "BarBar", "Foo", "QixQix", "8", "Foo", "Bar",
+ "11", "Foo", "Foo", "Qix", "FooBarBar", "16", "Qix", "Foo", "19", "Bar", "FooQix", "22", "Foo", "Foo",
+ "BarBar", "26", "FooQix", "Qix", "29", "FooBarFoo", "Foo", "Foo", "FooFooFoo", "Foo", "BarQixFooBar",
+ "FooFoo", "FooQix", "Foo", "FooFoo", "Bar", "41", "FooQix", "Foo", "44", "FooBarBar", "46", "Qix", "Foo",
+ "Qix", "BarBar", "FooBar", "Bar", "BarFoo", "FooBar", "BarBarBar", "QixBar", "FooBarQix", "Bar", "Bar",
+ "FooBar", "61", "62", "FooQixFoo", "64", "BarBar", "Foo", "Qix", "68", "Foo", "BarQixQix", "Qix", "FooQix",
+ "QixFoo", "Qix", "FooBarQixBar", "Qix", "QixQixQix", "FooQix", "Qix", "Bar", "Foo", "82", "Foo", "FooQix",
+ "BarBar", "86", "FooQix", "88", "89", "FooBar", "Qix", "92", "FooFoo", "94", "BarBar", "Foo", "Qix", "Qix",
+ "Foo", "Bar" };
+
+ private int index;
+
+ private String result;
+
+ public FooBarQixAllTest(int index, String result) {
+ this.index = index;
+ this.result = result;
+ }
+
+ @Test
+ public void testFooBarQix() {
+ assertEquals(result, FooBarQix.getFooBarQix(index));
+ }
+
+}
View
77 foobarqix-maven-plugin/src/test/java/fr/linsolas/FooBarQixTest.java
@@ -0,0 +1,77 @@
+package fr.linsolas;
+
+import static fr.linsolas.FooBarQix.getFooBarQix;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Basic JUnit tests.
+ *
+ * @author Romain Linsolas
+ */
+public class FooBarQixTest {
+
+ @Test
+ public void value_unchanged() {
+ assertEquals("1", getFooBarQix(1));
+ assertEquals("2", getFooBarQix(2));
+ assertEquals("4", getFooBarQix(4));
+ assertEquals("8", getFooBarQix(8));
+ assertEquals("11", getFooBarQix(11));
+ }
+
+ @Test
+ public void return_foo_for_modulo_3() {
+ assertEquals("Foo", getFooBarQix(6));
+ assertEquals("Foo", getFooBarQix(12));
+ assertEquals("Foo", getFooBarQix(18));
+ assertEquals("Foo", getFooBarQix(24));
+ }
+
+ @Test
+ public void return_bar_for_modulo_5() {
+ assertEquals("Bar", getFooBarQix(10));
+ assertEquals("Bar", getFooBarQix(20));
+ assertEquals("Bar", getFooBarQix(40));
+ }
+
+ @Test
+ public void return_qix_for_modulo_7() {
+ assertEquals("Qix", getFooBarQix(14));
+ assertEquals("Qix", getFooBarQix(28));
+ assertEquals("Qix", getFooBarQix(49));
+ }
+
+ @Test
+ public void return_foo_for_starting_with_3() {
+ assertEquals("Foo", getFooBarQix(31));
+ assertEquals("Foo", getFooBarQix(32));
+ assertEquals("Foo", getFooBarQix(34));
+ assertEquals("Foo", getFooBarQix(38));
+ }
+
+ @Test
+ public void return_bar_for_starting_with_5() {
+ assertEquals("Bar", getFooBarQix(52));
+ assertEquals("Bar", getFooBarQix(58));
+ assertEquals("Bar", getFooBarQix(59));
+ }
+
+ @Test
+ public void return_qix_for_starting_with_7() {
+ assertEquals("Qix", getFooBarQix(71));
+ assertEquals("Qix", getFooBarQix(74));
+ assertEquals("Qix", getFooBarQix(76));
+ }
+
+ @Test
+ public void test_mixed() {
+ assertEquals("FooFoo", getFooBarQix(3));
+ assertEquals("BarBar", getFooBarQix(5));
+ assertEquals("QixQix", getFooBarQix(7));
+ assertEquals("FooBarBar", getFooBarQix(15));
+ assertEquals("FooQix", getFooBarQix(21));
+ }
+
+}
View
30 usage/pom.xml
@@ -0,0 +1,30 @@
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>fr.linsolas.foobarqix</groupId>
+ <artifactId>foobarqix-mvn-usage</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+ <name>foobarqix-maven-plugin usage</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>fr.linsolas.foobarqix</groupId>
+ <artifactId>foobarqix-maven-plugin</artifactId>
+ <version>1.0</version>
+ <configuration>
+ <from>1</from>
+ <to>100</to>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>foobarqix</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>

0 comments on commit 5b9759e

Please sign in to comment.