1
1
package com .zenuml .dsl ;
2
2
3
+ import com .zenuml .license .CheckLicense ;
4
+ import org .junit .Before ;
3
5
import org .junit .Test ;
6
+ import org .junit .runner .RunWith ;
7
+ import org .mockito .Mockito ;
8
+ import org .powermock .api .mockito .PowerMockito ;
9
+ import org .powermock .core .classloader .annotations .PrepareForTest ;
10
+ import org .powermock .modules .junit4 .PowerMockRunner ;
4
11
5
12
import static org .hamcrest .core .Is .is ;
6
13
import static org .junit .Assert .assertEquals ;
7
14
import static org .junit .Assert .assertThat ;
8
15
16
+ @ RunWith (PowerMockRunner .class )
17
+ @ PrepareForTest (CheckLicense .class )
9
18
public class ZenDslTest {
10
19
20
+ @ Before
21
+ public void setUp () {
22
+ PowerMockito .mockStatic (CheckLicense .class );
23
+ }
24
+
11
25
@ Test
12
26
public void testEscape () {
13
27
// remove the following characters: \, ", \n, \t, \r, `
@@ -18,6 +32,7 @@ public void testEscape() {
18
32
19
33
@ Test
20
34
public void test_quoted () {
35
+ Mockito .when (CheckLicense .isLicensed ()).thenReturn (true );
21
36
assertThat (new ZenDsl ().quoted ("a" ).getDsl (), is ("\" a\" " ));
22
37
assertThat (new ZenDsl ().quoted ("a\n b" ).getDsl (), is ("\" ab\" " ));
23
38
assertThat (new ZenDsl ()
@@ -28,10 +43,23 @@ public void test_quoted() {
28
43
29
44
@ Test
30
45
public void addComment () {
46
+ Mockito .when (CheckLicense .isLicensed ()).thenReturn (true );
31
47
assertThat (new ZenDsl ().comment ("a" ).getDsl (), is ("// a\n " ));
32
48
assertThat (new ZenDsl ().comment ("a\n b" ).getDsl (), is ("// a\n // b\n " ));
33
49
assertThat (new ZenDsl ()
34
50
.startBlock ().comment ("a\n b" )
35
51
.closeBlock ().getDsl (), is (" {\n \t // a\n \t // b\n }\n " ));
36
52
}
53
+
54
+ @ Test
55
+ public void testNotLicensed () {
56
+ Mockito .when (CheckLicense .isLicensed ()).thenReturn (false );
57
+ assertThat (new ZenDsl ().getDsl (), is (ZenDsl .LICENSE_IS_NOT_VALID ));
58
+ }
59
+
60
+ @ Test
61
+ public void testNotLicensedWithNull () {
62
+ Mockito .when (CheckLicense .isLicensed ()).thenReturn (null );
63
+ assertThat (new ZenDsl ().getDsl (), is (ZenDsl .LICENSE_IS_NOT_VALID ));
64
+ }
37
65
}
0 commit comments