本文整理汇总了Java中org.hamcrest.MatcherAssert类的典型用法代码示例。如果您正苦于以下问题:Java MatcherAssert类的具体用法?Java MatcherAssert怎么用?Java MatcherAssert使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MatcherAssert类属于org.hamcrest包,在下文中一共展示了MatcherAssert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
@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")
)
);
}
示例2: skipIterable
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
@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"
)
);
}
示例3: createsMapWithFunctions
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
@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)
);
}
示例4: readsBinaryResource
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
@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,
}
)
);
}
示例5: equalsAndHashCode
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
/**
* 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)
);
}
示例6: assertSize
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
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)
);
}
示例7: readsInputIntoBytes
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
@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("друг!")
)
);
}
示例8: startsUnknownCommand
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
/**
* 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)
);
}
示例9: runsAsProcInBackground
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
@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)
)
);
}
示例10: iteratesOverFirstPage
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
/**
* 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")
);
}
示例11: partitionedOne
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
@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)
)
)
);
}
示例12: testEnums
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
@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));
}
示例13: readsInputIntoBytesWithSmallBuffer
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
@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("товарищ!")
)
);
}
示例14: getFlattenedEnclosingElementsTree_withoutRoot_withMaxDepth
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
@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)));
}
开发者ID:toolisticon,项目名称:annotation-processor-toolkit,代码行数:23,代码来源:ElementUtils_AccessEnclosingElementsTest.java
示例15: ignoresChangesInMap
import org.hamcrest.MatcherAssert; //导入依赖的package包/类
@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())
);
}