Add a Broker pojo

This commit is contained in:
R. Tyler Croy 2015-09-02 11:48:03 -07:00
parent d6aac679b5
commit 3f6601b18c
No known key found for this signature in database
GPG Key ID: 1426C7DC3F51E16F
3 changed files with 118 additions and 0 deletions

View File

@ -32,3 +32,13 @@ idea {
downloadSources = true
}
}
test {
testLogging {
exceptionFormat = 'full'
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}
assemble.dependsOn check
install.dependsOn assemble

View File

@ -0,0 +1,57 @@
package com.github.reiseburo.beetle;
/**
* Simple POJO containing informtaion about a Kafka broker
*/
public class Broker {
private String host;
private int port;
private int jmxPort;
public String getHost() {
return this.host;
}
public int getPort() {
return port;
}
public int getJmxPort() {
return jmxPort;
}
public static class Builder {
private int port;
private int jmxPort;
private String host;
public Builder withHost(String hostName) {
this.host = hostName;
return this;
}
public Builder withPort(int port) {
this.port = port;
return this;
}
public Builder withJMXPort(int port) {
this.jmxPort = port;
return this;
}
public Broker build() {
return new Broker(this);
}
}
public static Builder builder() {
return new Builder();
}
private Broker(Builder builder) {
this.host = builder.host;
this.port = builder.port;
this.jmxPort = builder.jmxPort;
}
}

View File

@ -0,0 +1,51 @@
package com.github.reiseburo.beetle
import spock.lang.*
/**
*/
class BrokerSpec extends Specification {
}
class BrokerBuilderSpec extends Specification {
def "builder() pattern should create a Broker"() {
expect:
Broker.builder().build() instanceof Broker
}
def "withHost()"() {
given:
final String hostName = 'localhost'
Broker broker
when:
broker = Broker.builder().withHost(hostName).build()
then:
broker.host == hostName
}
def "withPort()"() {
given:
final int port = 1234
Broker broker
when:
broker = Broker.builder().withPort(port).build()
then:
broker.port == port
}
def "withJMXPort()"() {
given:
final int port = 1234
Broker broker
when:
broker = Broker.builder().withJMXPort(port).build()
then:
broker.jmxPort == port
}
}