1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package com.jcabi.github.mock;
31
32 import com.jcabi.github.Branch;
33 import com.jcabi.github.Coordinates;
34 import com.jcabi.github.Repo;
35 import java.io.IOException;
36 import java.util.Iterator;
37 import org.hamcrest.MatcherAssert;
38 import org.hamcrest.Matchers;
39 import org.junit.Test;
40
41
42
43
44
45
46
47 public final class MkBranchesTest {
48
49
50
51
52 @Test
53 public void createsBranch() throws IOException {
54 final String name = "my-new-feature";
55 final String sha = "590e188e3d52a8da38cf51d3f9bf598bb46911af";
56 final Repo repo = new MkGithub().randomRepo();
57 final Branch branch = ((MkBranches) repo.branches())
58 .create(name, sha);
59 MatcherAssert.assertThat(branch.name(), Matchers.equalTo(name));
60 MatcherAssert.assertThat(
61 branch.commit().sha(),
62 Matchers.equalTo(sha)
63 );
64 final Coordinates coords = branch.commit().repo().coordinates();
65 MatcherAssert.assertThat(
66 coords.user(),
67 Matchers.equalTo(repo.coordinates().user())
68 );
69 MatcherAssert.assertThat(
70 coords.repo(),
71 Matchers.equalTo(repo.coordinates().repo())
72 );
73 }
74
75
76
77
78
79 @Test
80 public void iteratesOverBranches() throws IOException {
81 final MkBranches branches = (MkBranches) new MkGithub().randomRepo()
82 .branches();
83 final String onename = "narf";
84 final String onesha = "a86da33b875e8ecbaf75cefcf6d8957cbecb654e";
85 branches.create(onename, onesha);
86 final String twoname = "zort";
87 final String twosha = "ba00fa4fe331c59736b87f52f760e1ccfb293b5f";
88 branches.create(twoname, twosha);
89 MatcherAssert.assertThat(
90 branches.iterate(),
91 Matchers.<Branch>iterableWithSize(2)
92 );
93 final Iterator<Branch> iter = branches.iterate().iterator();
94 final Branch one = iter.next();
95 MatcherAssert.assertThat(one.name(), Matchers.equalTo(onename));
96 MatcherAssert.assertThat(
97 one.commit().sha(),
98 Matchers.equalTo(onesha)
99 );
100 final Branch two = iter.next();
101 MatcherAssert.assertThat(two.name(), Matchers.equalTo(twoname));
102 MatcherAssert.assertThat(
103 two.commit().sha(),
104 Matchers.equalTo(twosha)
105 );
106 }
107 }