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.
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
;
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. */
36 public ExpectedException thrown
= ExpectedException
.none();
40 * Test method for {@link RuleBuilderImplementation#then(Conclusion)}
43 * Ensures that rules can be created with a valid RuleBuilderImplementation.
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()));
58 * Test method for {@link RuleBuilderImplementation#when(Predicate)}
61 * Ensures that no <code>null</code> premise can be used.
65 public void shouldNotAcceptNullPredicate() {
66 final RuleBuilder
<Context
<Object
>> builder
= new RuleBuilderImplementation
<>();
68 thrown
.expect(NullPointerException
.class);
75 * Test method for {@link RuleBuilderImplementation#then(Conclusion)}
78 * Ensures that no <code>null</code> conclusion can be used.
82 public void shouldNotAcceptNullConclusion() {
83 final RuleBuilder
<Context
<Object
>> builder
= new RuleBuilderImplementation
<>();
85 thrown
.expect(NullPointerException
.class);
92 * Test method for {@link RuleBuilderImplementation#called(String)}
95 * Ensures that no <code>null</code> string can be used.
99 public void shouldNotAcceptNullName() {
100 final RuleBuilder
<Context
<Object
>> builder
= new RuleBuilderImplementation
<>();
102 thrown
.expect(NullPointerException
.class);
104 builder
.called(null);