@Test
public void test() throws IOException {
MatcherAssert.assertThat(
"Incorrect query map produced.",
new WallPostFromGroup(
new WallPostBase(
new VkApiClient(
new TransportClientCached(
""
)
),
new UserActor(
0,
"1"
)
)
).construct().build(),
Matchers.allOf(
Matchers.hasEntry("access_token", "1"),
Matchers.hasEntry("v", "5.63"),
Matchers.hasEntry("from_group", "1")
)
);
}
java类org.hamcrest.MatcherAssert的实例源码
WallPostFromGroupTest.java 文件源码
项目:VKMusicUploader
阅读 23
收藏 0
点赞 0
评论 0
SkippedTest.java 文件源码
项目:cactoos
阅读 22
收藏 0
点赞 0
评论 0
@Test
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public void skipIterable() throws Exception {
MatcherAssert.assertThat(
"Can't skip elements in iterable",
new Skipped<>(
2, new IterableOf<>(
"one", "two", "three", "four"
)
),
Matchers.contains(
"three",
"four"
)
);
}
MapOfTest.java 文件源码
项目:cactoos
阅读 22
收藏 0
点赞 0
评论 0
@Test
public void createsMapWithFunctions() {
MatcherAssert.assertThat(
"Can't create a map with functions as values",
new MapOf<Integer, Scalar<Boolean>>(
new MapEntry<>(0, () -> true),
new MapEntry<>(
1,
() -> {
throw new IOException("oops");
}
)
),
Matchers.hasKey(0)
);
}
ResourceOfTest.java 文件源码
项目:cactoos
阅读 26
收藏 0
点赞 0
评论 0
@Test
public void readsBinaryResource() throws Exception {
MatcherAssert.assertThat(
"Can't read bytes from a classpath resource",
Arrays.copyOfRange(
new BytesOf(
new ResourceOf(
"org/cactoos/io/ResourceOfTest.class"
)
).asBytes(),
// @checkstyle MagicNumber (2 lines)
0,
4
),
Matchers.equalTo(
new byte[]{
// @checkstyle MagicNumber (1 line)
(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE,
}
)
);
}
ScalarTest.java 文件源码
项目:camel
阅读 24
收藏 0
点赞 0
评论 0
/**
* Make sure that equals and hash code are reflexive
* and symmetric.
*/
@Test
public void equalsAndHashCode() {
final String val = "test scalar value";
final Scalar firstScalar = new Scalar(val);
final Scalar secondScalar = new Scalar(val);
MatcherAssert.assertThat(firstScalar, Matchers.equalTo(secondScalar));
MatcherAssert.assertThat(secondScalar, Matchers.equalTo(firstScalar));
MatcherAssert.assertThat(firstScalar, Matchers.equalTo(firstScalar));
MatcherAssert.assertThat(firstScalar,
Matchers.not(Matchers.equalTo(null)));
MatcherAssert.assertThat(
firstScalar.hashCode() == secondScalar.hashCode(), is(true)
);
}
MigrationFileAssetTest.java 文件源码
项目:Android-Migrator
阅读 24
收藏 0
点赞 0
评论 0
private static void assertSize(
final String file,
final int size
) throws IOException {
MatcherAssert.assertThat(
file,
Collections.list(
new IterableEnum<>(
new MigrationFileAsset(
RuntimeEnvironment.application.getAssets(),
new File("files", file)
).migrations()
)
),
Matchers.hasSize(size)
);
}
BytesOfTest.java 文件源码
项目:cactoos
阅读 24
收藏 0
点赞 0
评论 0
@Test
public void readsInputIntoBytes() throws IOException {
MatcherAssert.assertThat(
"Can't read bytes from Input",
new String(
new BytesOf(
new InputOf("Hello, друг!")
).asBytes(),
StandardCharsets.UTF_8
),
Matchers.allOf(
Matchers.startsWith("Hello, "),
Matchers.endsWith("друг!")
)
);
}
ConfusedTestCase.java 文件源码
项目:comdor
阅读 25
收藏 0
点赞 0
评论 0
/**
* Confused can start an 'unknown' command.
* @throws Exception If something goes wrong.
*/
@Test
public void startsUnknownCommand() throws Exception {
final Command com = Mockito.mock(Command.class);
Mockito.when(com.type()).thenReturn("unknown");
Mockito.when(com.language()).thenReturn(new English());
final Knowledge confused = new Confused();
Steps steps = confused.start(com, Mockito.mock(Log.class));
MatcherAssert.assertThat(steps, Matchers.notNullValue());
MatcherAssert.assertThat(
steps instanceof GithubSteps, Matchers.is(true)
);
}
AsyncFuncTest.java 文件源码
项目:cactoos
阅读 24
收藏 0
点赞 0
评论 0
@Test
public void runsAsProcInBackground() {
MatcherAssert.assertThat(
"Can't run proc in the background",
input -> {
final CountDownLatch latch = new CountDownLatch(1);
new AsyncFunc<>(
(Proc<Boolean>) ipt -> latch.countDown()
).exec(input);
latch.await();
return true;
},
new FuncApplies<>(
true, Matchers.equalTo(true)
)
);
}
RepositoriesPageTestCase.java 文件源码
项目:versioneye-api
阅读 22
收藏 0
点赞 0
评论 0
/**
* RepositoriesPage can return the first page of repositories.
* @throws Exception If something goes wrong.
*/
@Test
public void iteratesOverFirstPage() throws Exception {
final MkContainer container =
this.mockVersionEyeRepositories().start();
final VersionEye versionEye = new RtVersionEye(
new JdkRequest(container.home())
);
List<Repository> first =
versionEye.github().repositories().paginated().fetch();
MatcherAssert.assertThat(first.size(), Matchers.is(14));
MatcherAssert.assertThat(
first.get(0).name(),
Matchers.equalTo("Compiler")
);
MatcherAssert.assertThat(
first.get(13).name(),
Matchers.equalTo("versioneye-api")
);
MatcherAssert.assertThat(
container.take().uri().toString(),
Matchers.equalTo("/github?page=1")
);
}
PartitionedTest.java 文件源码
项目:cactoos
阅读 26
收藏 0
点赞 0
评论 0
@Test
public void partitionedOne() {
MatcherAssert.assertThat(
"Can't generate a Partitioned of partition size 1.",
new ArrayList<>(
new ListOf<>(
new Partitioned<>(1, Arrays.asList(1, 2, 3).iterator())
)
),
Matchers.equalTo(
Arrays.asList(
Collections.singletonList(1), Collections.singletonList(2),
Collections.singletonList(3)
)
)
);
}
TestEnums.java 文件源码
项目:polymorphia
阅读 26
收藏 0
点赞 0
评论 0
@Test
public void testEnums() {
Codec<Pojo> pojoCodec = codecRegistry.get(Pojo.class);
LovelyDisplayable lovelyDisplayable = LovelyDisplayable.builder().identityProperty("foo").build();
Pojo pojo = Pojo.builder()
.simpleEnumProperty(EnumA.TYPE1)
.displayable(Arrays.asList(EnumB.TYPE1, EnumA.TYPE1, EnumA.TYPE3, lovelyDisplayable))
.build();
StringWriter stringWriter = new StringWriter();
JsonWriter writer = new JsonWriter(stringWriter, new JsonWriterSettings(true));
pojoCodec.encode(writer, pojo, EncoderContext.builder().build());
System.out.println(stringWriter.toString());
Pojo decodedPojo = pojoCodec.decode(new JsonReader(stringWriter.toString()), DecoderContext.builder().build());
MatcherAssert.assertThat(decodedPojo.getDisplayable(),
IsIterableContainingInOrder.contains(EnumB.TYPE1, EnumA.TYPE1, EnumA.TYPE3, lovelyDisplayable));
}
BytesOfTest.java 文件源码
项目:cactoos
阅读 25
收藏 0
点赞 0
评论 0
@Test
public void readsInputIntoBytesWithSmallBuffer() throws IOException {
MatcherAssert.assertThat(
"Can't read bytes from Input with a small reading buffer",
new String(
new BytesOf(
new InputOf(
new TextOf("Hello, товарищ!")
),
2
).asBytes(),
StandardCharsets.UTF_8
),
Matchers.allOf(
Matchers.startsWith("Hello,"),
Matchers.endsWith("товарищ!")
)
);
}
ElementUtils_AccessEnclosingElementsTest.java 文件源码
项目:annotation-processor-toolkit
阅读 25
收藏 0
点赞 0
评论 0
@Test
public void getFlattenedEnclosingElementsTree_withoutRoot_withMaxDepth() {
// Prepare
Element parameterElement = Mockito.mock(VariableElement.class);
Element methodElement = Mockito.mock(ExecutableElement.class);
Element typeElement = Mockito.mock(TypeElement.class);
Element packageElement = Mockito.mock(PackageElement.class);
Mockito.when(parameterElement.getEnclosingElement()).thenReturn(methodElement);
Mockito.when(methodElement.getEnclosingElement()).thenReturn(typeElement);
Mockito.when(typeElement.getEnclosingElement()).thenReturn(packageElement);
// execute
List<Element> result = ElementUtils.AccessEnclosingElements.getFlattenedEnclosingElementsTree(parameterElement, false, 2);
// validate
MatcherAssert.assertThat(result, Matchers.containsInAnyOrder(methodElement, typeElement));
MatcherAssert.assertThat(result, Matchers.not(Matchers.contains(parameterElement, packageElement)));
}
StickyMapTest.java 文件源码
项目:cactoos
阅读 28
收藏 0
点赞 0
评论 0
@Test
public void ignoresChangesInMap() throws Exception {
final AtomicInteger size = new AtomicInteger(2);
final Map<Integer, Integer> map = new StickyMap<>(
new MapOf<>(
() -> new Repeated<>(
size.incrementAndGet(), () -> new MapEntry<>(
new SecureRandom().nextInt(),
1
)
)
)
);
MatcherAssert.assertThat(
"Can't ignore the changes in the underlying map",
map.size(),
Matchers.equalTo(map.size())
);
}
RtYamlMappingTest.java 文件源码
项目:camel
阅读 23
收藏 0
点赞 0
评论 0
/**
* RtYamlMapping can return null if the specified key is missig.
*/
@Test
public void returnsNullOnMissingKey() {
Map<YamlNode, YamlNode> mappings = new HashMap<>();
mappings.put(new Scalar("key3"), Mockito.mock(YamlSequence.class));
mappings.put(new Scalar("key1"), Mockito.mock(YamlMapping.class));
RtYamlMapping map = new RtYamlMapping(mappings);
MatcherAssert.assertThat(
map.yamlSequence("key4"), Matchers.nullValue()
);
MatcherAssert.assertThat(
map.yamlMapping("key4"), Matchers.nullValue()
);
MatcherAssert.assertThat(
map.string("key4"), Matchers.nullValue()
);
MatcherAssert.assertThat(
map.yamlSequence("key1"), Matchers.nullValue()
);
}
AndWithIndexTest.java 文件源码
项目:cactoos
阅读 26
收藏 0
点赞 0
评论 0
@Test
public void iteratesListWithIndex() {
final List<String> list = new LinkedList<>();
MatcherAssert.assertThat(
"Can't iterate a list with a procedure",
new AndWithIndex(
new BiFuncOf<>(
(text, index) -> list.add(index, text),
true
),
"hello", "world"
),
new ScalarHasValue<>(
Matchers.allOf(
Matchers.equalTo(true),
new MatcherOf<>(
value -> list.size() == 2
)
)
)
);
}
DateOfTest.java 文件源码
项目:cactoos
阅读 32
收藏 0
点赞 0
评论 0
@Test
public final void testParsingCustomFormattedStringToDate() {
MatcherAssert.assertThat(
"Can't parse a Date with custom format.",
new DateOf(
"2017-12-13 14:15:16.000000017",
"yyyy-MM-dd HH:mm:ss.n"
).value(),
Matchers.is(
Date.from(
LocalDateTime.of(
2017, 12, 13, 14, 15, 16, 17
).toInstant(ZoneOffset.UTC)
)
)
);
}
SupplyITCase.java 文件源码
项目:cedato-api-client
阅读 27
收藏 0
点赞 0
评论 0
/**
* Check supply count.
* @throws Exception If fails
* @checkstyle MagicNumberCheck (50 lines)
*/
@Test
public void supplyCount() throws Exception {
MatcherAssert.assertThat(
new LengthOf(
new Auth.Simple(
System.getProperty("failsafe.cedato.service"),
System.getProperty("failsafe.cedato.secret")
)
.cedato()
.reports()
.supplies()
.extended()
.supply(
Integer.parseInt(
System.getProperty("failsafe.cedato.supplyId")
)
)
.range(
LocalDateTime.of(2017, 10, 9, 13, 0, 0)
.atZone(ZoneOffset.UTC),
LocalDateTime.of(2017, 10, 9, 13, 59, 59)
.atZone(ZoneOffset.UTC)
)
.group("player_hour_subid")
.limit(10000)
).value(),
CoreMatchers.equalTo(4478)
);
}
ReadPipeScalarTest.java 文件源码
项目:camel
阅读 27
收藏 0
点赞 0
评论 0
/**
* ReadPipeScalar can compare itself to a Mapping.
*/
@Test
public void comparesToMapping() {
final List<YamlLine> lines = new ArrayList<>();
lines.add(new RtYamlLine("First Line.", 1));
lines.add(new RtYamlLine("Second Line.", 2));
lines.add(new RtYamlLine("Third Line.", 3));
final ReadPipeScalar scalar =
new ReadPipeScalar(new RtYamlLines(lines));
RtYamlMapping map = new RtYamlMapping(
new HashMap<YamlNode, YamlNode>()
);
MatcherAssert.assertThat(scalar.compareTo(map), Matchers.lessThan(0));
}
ReversedTextTest.java 文件源码
项目:cactoos
阅读 23
收藏 0
点赞 0
评论 0
@Test
public void reversedEmptyTextIsEmptyText() {
MatcherAssert.assertThat(
"Can't reverse empty text",
new ReversedText(
new TextOf("")
),
new TextHasString("")
);
}
MappedTest.java 文件源码
项目:cactoos
阅读 22
收藏 0
点赞 0
评论 0
@Test
public void transformsEmptyList() {
MatcherAssert.assertThat(
"Can't transform an empty iterable",
new Mapped<String, Text>(
input -> new UpperText(new TextOf(input)),
Collections.emptyList()
),
Matchers.emptyIterable()
);
}
ModelPathResolverTest.java 文件源码
项目:annotation-processor-toolkit
阅读 23
收藏 0
点赞 0
评论 0
@Test
public void getGetter_testDifferentKindOfGetterPrefixes() {
MatcherAssert.assertThat(ModelPathResolver.getGetter(new GetGetterTestClass(), "isGetter"), Matchers.is("isIsGetter"));
MatcherAssert.assertThat(ModelPathResolver.getGetter(new GetGetterTestClass(), "getGetter"), Matchers.is("getGetGetter"));
MatcherAssert.assertThat(ModelPathResolver.getGetter(new GetGetterTestClass(), "hasGetter"), Matchers.is("hasHasGetter"));
}
LimitedTest.java 文件源码
项目:cactoos
阅读 24
收藏 0
点赞 0
评论 0
@Test
public void limitOfZeroProducesEmptyIterable() {
// @checkstyle MagicNumber (7 lines)
MatcherAssert.assertThat(
"Can't limit an iterable to zero items",
new Limited<>(
0, new IterableOf<>(0, 1, 2, 3, 4)
),
Matchers.iterableWithSize(0)
);
}
ElementUtils_CheckModifierOfElementTest.java 文件源码
项目:annotation-processor-toolkit
阅读 24
收藏 0
点赞 0
评论 0
@Test
public void testHasStrictfpModifier() {
Element e = Mockito.mock(Element.class);
Mockito.when(e.getModifiers()).thenReturn(Utilities.convertVarargsToSet(Modifier.STRICTFP));
MatcherAssert.assertThat("Modifier should be found", ElementUtils.CheckModifierOfElement.hasStrictfpModifier(e));
Mockito.when(e.getModifiers()).thenReturn(Utilities.convertVarargsToSet(Modifier.PRIVATE));
MatcherAssert.assertThat("Modifier should not be found", !ElementUtils.CheckModifierOfElement.hasStrictfpModifier(e));
// check null valued element
MatcherAssert.assertThat("Modifier should not be found for null valued elements", !ElementUtils.CheckModifierOfElement.hasStrictfpModifier(null));
}
JoinedTextTest.java 文件源码
项目:cactoos
阅读 25
收藏 0
点赞 0
评论 0
@Test
public void joinsTexts() throws IOException {
MatcherAssert.assertThat(
"Can't join texts",
new JoinedText(
new TextOf(" "),
new TextOf("foo"),
new TextOf("bar")
),
new TextHasString("foo bar")
);
}
IsBlankTest.java 文件源码
项目:cactoos
阅读 25
收藏 0
点赞 0
评论 0
@Test
public void determinesBlankText() {
MatcherAssert.assertThat(
"Can't determine an empty text with spaces",
new IsBlank(
new TextOf(" ")
),
new ScalarHasValue<>(Boolean.TRUE)
);
}
LastMentionTestCase.java 文件源码
项目:comdor
阅读 29
收藏 0
点赞 0
评论 0
/**
* Agent already replied once to the last comment.
* @throws Exception if something goes wrong.
*/
@Test
public void mentionAlreadyReplied() throws Exception {
final MkStorage storage = new MkStorage.Synced(new MkStorage.InFile());
final Repo repoMihai = new MkGithub(storage, "amihaiemil")
.repos().create(
new Repos.RepoCreate("amihaiemil.github.io", false)
);
final Issue mihai = repoMihai.issues()
.create("test issue", "body");
mihai.comments().post("@comdor hello!");
final Issue comdor = new MkGithub(storage, "comdor").repos()
.get(repoMihai.coordinates()).issues().get(mihai.number());
comdor.comments().post("@amihaiemil hi there");
mihai.comments().post("@someoneelse, please check that...");
try {
new LastMention(comdor);
Assert.fail("An IAE should have been thrown!");
} catch (final MentionLookupException mae) {
MatcherAssert.assertThat(
mae.getMessage(),
Matchers.equalTo("Last mention is already answered!")
);
}
}
ConfigFromFileTest.java 文件源码
项目:sunshine
阅读 22
收藏 0
点赞 0
评论 0
@Test
public void hasUnexpected() {
MatcherAssert.assertThat(
"Unexpected attribute was loaded",
!new ConfigFromFile(new ByteArrayInputStream("a =b".getBytes())).has("d")
);
}
RtProjectTestCase.java 文件源码
项目:versioneye-api
阅读 30
收藏 0
点赞 0
评论 0
/**
* RtProject can return the ids of its children.
*/
public void returnsChildIds() {
final Project project = new RtProject(
new FakeRequest(),
Mockito.mock(Team.class),
Json.createObjectBuilder()
.add(
"child_ids",
Json.createArrayBuilder()
.add("child1")
.add("child2")
.build()
)
.build()
);
MatcherAssert.assertThat(
project.childIds(),
Matchers.hasSize(2)
);
MatcherAssert.assertThat(
project.childIds().get(0),
Matchers.equalTo("child1")
);
MatcherAssert.assertThat(
project.childIds().get(1),
Matchers.equalTo("child2")
);
}