mirror of https://github.com/reiseburo/beetle
Add a Broker pojo
This commit is contained in:
parent
d6aac679b5
commit
3f6601b18c
10
build.gradle
10
build.gradle
|
@ -32,3 +32,13 @@ idea {
|
|||
downloadSources = true
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
testLogging {
|
||||
exceptionFormat = 'full'
|
||||
events "passed", "skipped", "failed", "standardOut", "standardError"
|
||||
}
|
||||
}
|
||||
|
||||
assemble.dependsOn check
|
||||
install.dependsOn assemble
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue