Updated code for Java 7
[reguloj.git] / src / test / java / com / github / sebhoss / reguloj / implementation / RuleBuilderImplementationTest.java
blob6915270a5a87f3de2e399c05adcadd79ddde6c6a
1 /* This program is free software. It comes without any warranty, to
2 * the extent permitted by applicable law. You can redistribute it
3 * and/or modify it under the terms of the Do What The Fuck You Want
4 * To Public License, Version 2, as published by Sam Hocevar. See
5 * http://sam.zoy.org/wtfpl/COPYING for more details.
6 */
7 package com.github.sebhoss.reguloj.implementation;
9 import org.hamcrest.core.Is;
10 import org.hamcrest.core.IsNull;
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.junit.rules.ExpectedException;
14 import org.mockito.Mockito;
16 import com.github.sebhoss.common.annotation.CompilerWarnings;
17 import com.github.sebhoss.reguloj.Conclusion;
18 import com.github.sebhoss.reguloj.Context;
19 import com.github.sebhoss.reguloj.Rule;
20 import com.github.sebhoss.reguloj.RuleBuilder;
21 import com.google.common.base.Predicate;
23 /**
24 * Test cases for the {@link RuleBuilderImplementation}.
26 * @see RuleBuilderImplementation
28 @SuppressWarnings({ CompilerWarnings.NULL, CompilerWarnings.STATIC_METHOD })
29 public final class RuleBuilderImplementationTest {
31 /** Constant name for all rules inside this test. */
32 private static final String NAME = "test rule"; //$NON-NLS-1$
34 /** Checks expected exception inside single test cases. */
35 @org.junit.Rule
36 public ExpectedException thrown = ExpectedException.none();
38 /**
39 * <p>
40 * Test method for {@link RuleBuilderImplementation#then(Conclusion)}
41 * </p>
42 * <p>
43 * Ensures that rules can be created with a valid RuleBuilderImplementation.
44 * </p>
46 @Test
47 public void shouldCreateRuleIfAllValuesAreSet() {
48 final RuleBuilder<Context<Object>> builder = new RuleBuilderImplementation<>();
49 builder.called(RuleBuilderImplementationTest.NAME).when(Mockito.mock(Predicate.class));
51 final Rule<Context<Object>> rule = builder.then(Mockito.mock(Conclusion.class));
53 Assert.assertThat(rule, Is.is(IsNull.notNullValue()));
56 /**
57 * <p>
58 * Test method for {@link RuleBuilderImplementation#when(Predicate)}
59 * </p>
60 * <p>
61 * Ensures that no <code>null</code> premise can be used.
62 * </p>
64 @Test
65 public void shouldNotAcceptNullPredicate() {
66 final RuleBuilder<Context<Object>> builder = new RuleBuilderImplementation<>();
68 thrown.expect(NullPointerException.class);
70 builder.when(null);
73 /**
74 * <p>
75 * Test method for {@link RuleBuilderImplementation#then(Conclusion)}
76 * </p>
77 * <p>
78 * Ensures that no <code>null</code> conclusion can be used.
79 * </p>
81 @Test
82 public void shouldNotAcceptNullConclusion() {
83 final RuleBuilder<Context<Object>> builder = new RuleBuilderImplementation<>();
85 thrown.expect(NullPointerException.class);
87 builder.then(null);
90 /**
91 * <p>
92 * Test method for {@link RuleBuilderImplementation#called(String)}
93 * </p>
94 * <p>
95 * Ensures that no <code>null</code> string can be used.
96 * </p>
98 @Test
99 public void shouldNotAcceptNullName() {
100 final RuleBuilder<Context<Object>> builder = new RuleBuilderImplementation<>();
102 thrown.expect(NullPointerException.class);
104 builder.called(null);