Skip to content

Commit 60c4d2a

Browse files
committed
Bring in Lombok.
1 parent f0540f5 commit 60c4d2a

File tree

4 files changed

+43
-35
lines changed

4 files changed

+43
-35
lines changed

build.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,18 @@
9090
<delete file="cache.properties"/>
9191
</target>
9292

93-
<target name="javadoc" description="Generate Javadoc HTML.">
93+
<target name="javadoc" depends="resolve,compile"
94+
description="Generate documentation.">
95+
<taskdef classname="lombok.delombok.ant.DelombokTask" name="delombok"
96+
classpathref="build.classpath"/>
97+
<delombok verbose="true" to="${build.dir}/src" from="${src.dir}">
98+
<classpath refid="build.classpath"/>
99+
</delombok>
94100
<javadoc destdir="${dist.dir}/javadoc"
95101
link="http://download.oracle.com/javase/6/docs/api/"
96-
sourcepath="${src.dir}"/>
102+
sourcepath="${build.dir}/src">
103+
<classpath refid="build.classpath"/>
104+
</javadoc>
97105
</target>
98106

99107
<target name="format" description="Run the indenter on all source files.">

ivy.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
conf="default->default"/>
1212
<dependency org="junit" name="junit" rev="4.10"
1313
conf="test->default"/>
14+
<dependency org="org.projectlombok" name="lombok" rev="0.10.4"
15+
conf="build->default"/>
1416
<dependency org="com.puppycrawl.tools" name="checkstyle" rev="5.5"
1517
conf="build->default"/>
1618
</dependencies>

src/sample/java/project/SampleJavaProject.java

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,34 @@
22

33
import java.util.Timer;
44
import java.util.TimerTask;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
import lombok.NonNull;
9+
import lombok.Setter;
510
import org.apache.commons.cli.CommandLine;
611
import org.apache.commons.cli.GnuParser;
712
import org.apache.commons.cli.HelpFormatter;
813
import org.apache.commons.cli.Option;
914
import org.apache.commons.cli.Options;
1015

1116
/**
12-
* The main class.
13-
*
14-
* This is the main class of the application. It contains the main()
15-
* method, the first method called.
17+
* The main class of the application. It contains the main() method,
18+
* the first method called.
1619
*/
20+
@NoArgsConstructor
21+
@AllArgsConstructor
1722
public class SampleJavaProject extends TimerTask {
1823

1924
/** The delay between printed messages. */
2025
private static final long PRINT_DELAY = 1000L;
2126

2227
/** The name to printed in the output message. */
23-
private static String name = "world";
28+
@Getter @Setter @NonNull
29+
private String name = "world";
2430

2531
/**
26-
* The main class.
27-
*
2832
* Print the "Hello, world!" string.
29-
*
3033
* @param args application input arguments
3134
*/
3235
public static void main(final String[] args) {
@@ -44,37 +47,26 @@ public static void main(final String[] args) {
4447
}
4548

4649
/* Handle each argument. */
50+
SampleJavaProject sjp;
4751
if (line.hasOption("help")) {
4852
HelpFormatter formatter = new HelpFormatter();
4953
formatter.printHelp("SampleJavaProject [options]", options);
5054
System.exit(0);
5155
}
5256
if (line.hasOption("name")) {
53-
name = line.getOptionValue("name");
57+
sjp = new SampleJavaProject(line.getOptionValue("name"));
58+
} else {
59+
sjp = new SampleJavaProject();
5460
}
5561
if (line.hasOption("loop")) {
56-
new Timer().schedule(new SampleJavaProject(), 0L, PRINT_DELAY);
62+
new Timer().schedule(sjp, 0L, PRINT_DELAY);
5763
} else {
58-
new SampleJavaProject().run();
64+
sjp.run();
5965
}
6066
}
6167

6268
@Override
6369
public final void run() {
6470
System.out.printf("Hello, %s!\n", name);
6571
}
66-
67-
/**
68-
* Add two integers together.
69-
*
70-
* This is a dumb method that is here for the purposed of unit
71-
* testing.
72-
*
73-
* @param a first number
74-
* @param b second number
75-
* @return sum of the numbers
76-
*/
77-
public final int add(final int a, final int b) {
78-
return a + b;
79-
}
8072
}

test/sample/java/project/SampleJavaProjectTest.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package sample.java.project;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNull;
45
import org.junit.Before;
56
import org.junit.Test;
67

78
/**
8-
* A sample JUnit test.
9-
*
10-
* This test exists as a placeholder for the test unit framework.
9+
* Sample JUnit tests.
1110
*/
1211
public class SampleJavaProjectTest {
1312

@@ -25,12 +24,19 @@ public final void setUp() {
2524
}
2625

2726
/**
28-
* Tests the add() method in the main class.
27+
* Tests the generated setter and getter methods.
2928
*/
3029
@Test
31-
public final void testAdd() {
32-
assertEquals(sjp.add(3, 4), 7);
33-
assertEquals(sjp.add(5, -5), 0);
34-
assertEquals(sjp.add(-3, 4), 1);
30+
public final void testGetSet() {
31+
sjp.setName("foo");
32+
assertEquals("foo", sjp.getName());
33+
}
34+
35+
/**
36+
* Tests that the null check in the setter.
37+
*/
38+
@Test(expected=NullPointerException.class)
39+
public final void nullTest() {
40+
sjp.setName(null);
3541
}
3642
}

0 commit comments

Comments
 (0)