Commits

Christophe Furmaniak committed 28901b6

init the token class that will be used during evaluation

Comments (0)

Files changed (2)

src/main/java/net/awl/acacia/tagresolver/Token.java

+package net.awl.acacia.tagresolver;
+import static com.google.common.base.Preconditions.*;
+/**
+ * User: cfurmaniak
+ * Date: 17/09/12
+ * Time: 20:27
+ */
+public class Token {
+    private final GroupOfServers servers;
+    private final Operation operation;
+
+    public Token(GroupOfServers servers) {
+        checkNotNull(servers,"the GroupOfServers object provided should not be null");
+        this.servers = servers;
+        this.operation = null;
+    }
+
+    public Token(Operation operation) {
+        checkNotNull(operation,"the Operation object provided should not be null");
+        this.operation = operation;
+        this.servers = null;
+    }
+
+    public static Token fromGroupOfServers(GroupOfServers servers) {
+        return new Token(servers);
+    }
+
+    public static Token fromOperation(Operation operation) {
+        return new Token(operation);
+    }
+
+    public boolean isOperation() {
+        return operation != null;
+    }
+
+    public boolean isGroupOfServers() {
+        return servers != null;
+    }
+}

src/test/java/net/awl/acacia/tagresolver/TestToken.java

+package net.awl.acacia.tagresolver;
+
+import com.google.common.collect.ImmutableSet;
+import net.awl.acacia.tagresolver.operations.Difference;
+import org.testng.annotations.Test;
+
+import java.util.Set;
+
+import static org.fest.assertions.Assertions.assertThat;
+/**
+ * User: cfurmaniak
+ * Date: 17/09/12
+ * Time: 20:32
+ */
+public class TestToken {
+
+    @Test(expectedExceptions = {NullPointerException.class})
+    public void shouldThrowNPEWithNullOperation() {
+        new Token((Operation)null);
+    }
+
+    @Test(expectedExceptions = {NullPointerException.class})
+    public void shouldThrowNPEWithNullGroupOfServers() {
+        new Token((GroupOfServers)null);
+    }
+
+    @Test
+    public void shouldReturnTrueIfItIsAnOperation() {
+        Token token = new Token(new Difference());
+        assertThat(token.isOperation()).isTrue();
+        assertThat(token.isGroupOfServers()).isFalse();
+    }
+
+    @Test
+    public void shouldReturnTrueIfItIsAGroupOfServers() {
+        Set<String> notNull = ImmutableSet.of("first", "second");
+        String desc = "dumb";
+        GroupOfServers gos = new GroupOfServers(desc, notNull,GroupType.UNDEF);
+        Token token = new Token(gos);
+        assertThat(token.isOperation()).isFalse();
+        assertThat(token.isGroupOfServers()).isTrue();
+    }
+}