Skip to content

Commit

Permalink
yegor256#370 Tests for DyRepos operations
Browse files Browse the repository at this point in the history
  • Loading branch information
longtimeago committed Oct 25, 2014
1 parent 9b540c2 commit 4f9e730
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/com/thindeck/dynamo/DyRepos.java
Expand Up @@ -37,6 +37,7 @@
import com.jcabi.dynamo.Item;
import com.jcabi.dynamo.QueryValve;
import com.jcabi.dynamo.Region;
import com.jcabi.dynamo.Table;
import com.thindeck.api.Repo;
import com.thindeck.api.Repos;
import java.io.IOException;
Expand All @@ -45,7 +46,7 @@
* Dynamo implementation of {@link Repos}.
* @author Krzysztof Krason (Krzysztof.Krason@gmail.com)
* @version $Id$
* @todo #322 Create test for this class when jcabi/jcabi-dynamo#13 is done.
* @todo #370 Create test for #add new repo
*/
public final class DyRepos implements Repos {
/**
Expand Down
32 changes: 32 additions & 0 deletions src/test/java/com/thindeck/dynamo/DyReposTest.java
Expand Up @@ -30,12 +30,14 @@
package com.thindeck.dynamo;

import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.Condition;
import com.jcabi.dynamo.Frame;
import com.jcabi.dynamo.Item;
import com.jcabi.dynamo.Region;
import com.jcabi.dynamo.Table;
import com.jcabi.dynamo.Valve;
import com.thindeck.api.Repo;
import com.thindeck.api.Repos;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
Expand All @@ -53,6 +55,30 @@
*/
public final class DyReposTest {

/**
* DyRepos can get single repo by name.
* @throws IOException In case of error.
*/
@Test
public void getRepoByName() throws IOException {
final String name = "repo_name";
final Repos repos = new DyRepos(this.region(name));
MatcherAssert.assertThat(
repos.get(name).name(), Matchers.is(name)
);
}

/**
* DyRepos throws exception on adding existing repo.
* @throws IOException In case of error.
*/
@Test(expected = IllegalArgumentException.class)
public void addExistingRepo() throws IOException {
final String name = "existing_repo_name";
final Repos repos = new DyRepos(this.region(name));
repos.add(name);
}

/**
* DyRepos can return single repos.
* @throws IOException In case of error.
Expand Down Expand Up @@ -103,6 +129,12 @@ private Region region(final String... names) throws IOException {
final Frame frame = Mockito.mock(Frame.class);
Mockito.when(region.table(Mockito.eq(DyRepo.TBL))).thenReturn(table);
Mockito.when(table.frame()).thenReturn(frame);
Mockito.when(frame.where(
Mockito.eq(DyRepo.ATTR_NAME), Mockito.any(String.class))
).thenReturn(frame);
Mockito.when(frame.where(
Mockito.eq(DyRepo.ATTR_NAME), Mockito.any(Condition.class))
).thenReturn(frame);
Mockito.when(frame.through(Mockito.any(Valve.class))).thenReturn(frame);
final Collection<Item> items = new LinkedList<Item>();
for (final String name : names) {
Expand Down

0 comments on commit 4f9e730

Please sign in to comment.