当前位置: 首页>>代码示例>>Java>>正文


Java BaseMatcher类代码示例

本文整理汇总了Java中org.hamcrest.BaseMatcher的典型用法代码示例。如果您正苦于以下问题:Java BaseMatcher类的具体用法?Java BaseMatcher怎么用?Java BaseMatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BaseMatcher类属于org.hamcrest包,在下文中一共展示了BaseMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
@Before
public void init() {
    audienceManagerService = mock(AudienceManagerService.class);
    authenticationManager = mock(AuthenticationManager.class);
    UserDetailsService userDetailsService = mock(UserDetailsService.class);
    TokenBasedRememberMeServices rememberMeServices = spy(new TokenBasedRememberMeServices("key", userDetailsService));
    provider = new AudienceManagerSecurityProvider(audienceManagerService, authenticationManager, rememberMeServices);

    token.setDetails("id");

    doThrow(new BadCredentialsException("Test")).when(authenticationManager).authenticate(any(Authentication.class));
    doReturn(token).when(authenticationManager).authenticate(argThat(new BaseMatcher<Authentication>() {
        @Override
        public boolean matches(Object item) {
            return ((Authentication) item).getPrincipal().equals("user");
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("Username is user");
        }
    }));
}
 
开发者ID:sdl,项目名称:dxa-modules,代码行数:24,代码来源:AudienceManagerSecurityProviderTest.java

示例2: hasFieldWithUserRef

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static <T> Matcher<T> hasFieldWithUserRef(final String fieldName, final User user) {
    return new BaseMatcher<T>() {
        @Override
        public boolean matches(Object o) {
            Ref<User> userRef = TestSupport.getField(o, fieldName);
            if (user == null) {
                return userRef == null;
            } else {
                String username = userRef.getKey().getName();

                return user.getUsername().equals(username);
            }
        }

        @Override
        public void describeTo(Description description) {
            description.appendText(String.format("User with username '%s' on field %s", user, fieldName));
        }
    };
}
 
开发者ID:3wks,项目名称:generator-thundr-gae-react,代码行数:21,代码来源:Matchers.java

示例3: containsLine

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
@Factory
@Deprecated
/**
 * Please avoid using as the hamcrest way of reporting error wraps a multi-line
 * text into a single line and makes hard to understand the problem.
 * Instead, please try to use the spock/groovy assert and {@link #containsLine(String, String)}
 */
public static Matcher<String> containsLine(final String line) {
    return new BaseMatcher<String>() {
        public boolean matches(Object o) {
            return containsLine(equalTo(line)).matches(o);
        }

        public void describeTo(Description description) {
            description.appendText("a String that contains line ").appendValue(line);
        }
    };
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:19,代码来源:Matchers.java

示例4: isSerializable

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
@Factory
public static Matcher<Object> isSerializable() {
    return new BaseMatcher<Object>() {
        public boolean matches(Object o) {
            try {
                new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(o);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return true;
        }

        public void describeTo(Description description) {
            description.appendText("is serializable");
        }
    };
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:18,代码来源:Matchers.java

示例5: getMatcher

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
private BaseMatcher<BindException> getMatcher(String message, String field) {
	return new BaseMatcher<BindException>() {

		@Override
		public void describeTo(Description description) {

		}

		@Override
		public boolean matches(Object item) {
			BindException ex = (BindException) ((Exception) item).getCause();
			ObjectError error = ex.getAllErrors().get(0);
			boolean messageMatches = message.equals(error.getDefaultMessage());
			if (field == null) {
				return messageMatches;
			}
			String fieldErrors = ((FieldError) error).getField();
			return messageMatches && fieldErrors.equals(field);
		}

	};
}
 
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:23,代码来源:ResourceServerPropertiesTests.java

示例6: within

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
private static Matcher within(double epsilon, double value) {
    return new BaseMatcher() {
        @Override
        public void describeTo(Description description) {
            description.appendText("within ")
                    .appendText(Double.toString(epsilon))
                    .appendText(" of ")
                    .appendText(Double.toString(value));
        }

        @Override
        public boolean matches(Object item) {
            return item instanceof Double && Math.abs(((Double)item) - value) < epsilon;
        }
    };
}
 
开发者ID:ragnard,项目名称:shen-truffle,代码行数:17,代码来源:KLambdaTest.java

示例7: isSameAs

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static Matcher<List<AuditLogEntry>> isSameAs(
        final List<AuditLog> auditLogs) {
    return new BaseMatcher<List<AuditLogEntry>>() {
        private int errorPosition;

        @Override
        public boolean matches(Object object) {
            List<AuditLogEntry> auditLogEntries = (List<AuditLogEntry>) object;

            assertEquals(auditLogEntries.size(), auditLogs.size());
            for (int i = 0; i < auditLogEntries.size(); i++) {
                errorPosition = i;
                compareAuditLogEntry(auditLogEntries.get(i),
                        auditLogs.get(i));
            }
            return true;
        }

        @Override
        public void describeTo(Description description) {
            description
                    .appendText("AuditLogEntry is not equal with AuditLog at position "
                            + errorPosition);
        }
    };
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:27,代码来源:AuditLogMatchers.java

示例8: sortedCreationTimes

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static Matcher<List<AuditLog>> sortedCreationTimes() {
    return new BaseMatcher<List<AuditLog>>() {

        @Override
        public boolean matches(Object object) {
            List<AuditLog> auditLogs = (List<AuditLog>) object;

            for (int i = 0; i < auditLogs.size()-1; i++) {
                assertTrue(auditLogs.get(i).getCreationTime()<=auditLogs.get(i+1).getCreationTime());
            }

            return true;
        }

        @Override
        public void describeTo(Description description) {
            description
                    .appendText("AuditLogEntry List not sorted on creation time.");
        }
    };
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:22,代码来源:AuditLogMatchers.java

示例9: notSortedCreationTimes

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static Matcher<List<AuditLog>> notSortedCreationTimes() {
    return new BaseMatcher<List<AuditLog>>() {

        @Override
        public boolean matches(Object object) {
            List<AuditLog> auditLogs = (List<AuditLog>) object;

            for (int i = 0; i < auditLogs.size()-1; i++) {
                if (auditLogs.get(i).getCreationTime()>auditLogs.get(i+1).getCreationTime()) {
                	return true;
                }
            }

            return false;
        }

        @Override
        public void describeTo(Description description) {
            description
                    .appendText("AuditLogEntry List sorted on creation time.");
        }
    };
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:24,代码来源:AuditLogMatchers.java

示例10: isCorrectTimeStampFormat

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static Matcher<String> isCorrectTimeStampFormat() {
    return new BaseMatcher<String>() {

        @Override
        public boolean matches(Object object) {
            String string = (String) object;
            assertTrue(string
                    .matches("[0-9]{2,}/[0-9]{2,}/[0-9]{4,}_[0-9]{2,}:[0-9]{2,}:[0-9]{2,}\\.[0-9]{3,}"));
            return true;
        }

        @Override
        public void describeTo(Description description) {
            description
                    .appendText("Timestamp format is wrong. MM/dd/YYYY_hh:mm:ss.SSS expected");
        }
    };
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:AuditLogMatchers.java

示例11: hasContent

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static Matcher<? super HttpResponse> hasContent(final String content, final String charset) {
    return new BaseMatcher<HttpResponse>() {
        public boolean matches(Object o) {
            try {
                HttpResponse response = (HttpResponse) o;
                Reader reader = new InputStreamReader(response.getEntity().getContent(), charset);

                int intValueOfChar;
                String targetString = "";
                while ((intValueOfChar = reader.read()) != -1) {
                    targetString += (char) intValueOfChar;
                }
                reader.close();

                return targetString.equals(content);
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }

        public void describeTo(Description description) {
            description.appendText(content);
        }
    };
}
 
开发者ID:PawelAdamski,项目名称:HttpClientMock,代码行数:27,代码来源:HttpResponseMatchers.java

示例12: getGraph

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
/**
 * @return the graph
 */
public GWGraph getGraph() {
	if (graph==null) {
		 List<SWTBotGefEditPart> parts = editor.editParts(new BaseMatcher<EditPart>() {
			@Override
			public boolean matches(Object item) {
				if (item instanceof org.gw4e.eclipse.studio.part.editor.GraphPart) return true;
				if (item instanceof org.gw4e.eclipse.studio.part.editor.VertexPart) return true;
				if (item instanceof org.gw4e.eclipse.studio.part.editor.EdgePart) return true;
				return false;
			}
			@Override
			public void describeTo(Description description) {
			}
		});
		 
		if (parts==null || parts.size() ==0) {
			throw new RuntimeException("Empty Graph");
		}
		graph = getGraph (parts.get(0));	
	}
	return graph;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:26,代码来源:Graph.java

示例13: equalToMensas

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
private Matcher<List<Mensa>> equalToMensas(List<Mensa> mensas) {
	return new BaseMatcher<List<Mensa>>() {
		@Override
		@SuppressWarnings("unchecked")
		public boolean matches(Object item) {
			List<Mensa> matchTargetList = (List<Mensa>) item;
			if (matchTargetList.size() != mensas.size()) {
				return false;
			} else {
				for (int i = 0; i < mensas.size(); i++) {
					Mensa mensa = mensas.get(i);
					Mensa matchTarget = matchTargetList.get(i);
					if (!EqualsBuilder.reflectionEquals(mensa, matchTarget, Arrays.asList("updatedAt"))) {
						return false;
					}
				}
				return true;
			}
		}

		@Override
		public void describeTo(Description description) {
			description.appendText("each mensa should be equal except for the update value");
		}
	};
}
 
开发者ID:xabgesagtx,项目名称:mensa-api,代码行数:27,代码来源:MensaScraperTest.java

示例14: captureCreatedRadiator

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static BaseMatcher<String> captureCreatedRadiator(CreatedRadiator createdRadiator) {
    return new BaseMatcher<String>() {

        @Override
        public boolean matches(Object o) {
            try {
                CreatedRadiator cr = new ObjectMapper().readValue((String) o, CreatedRadiator.class);
                createdRadiator.code = cr.code;
                createdRadiator.secret = cr.secret;
            } catch (IOException e) {
                fail("IOE encountered " + e.getMessage());
            }
            return true;
        }

        @Override
        public void describeTo(Description description) {
        }
    };
}
 
开发者ID:BuildRadiator,项目名称:BuildRadiator,代码行数:21,代码来源:HasNewRadiator.java

示例15: equalsVideoDataInCursor

import org.hamcrest.BaseMatcher; //导入依赖的package包/类
/**
 * Checks that the given {@code VideoLibraryModel.Video} is equal to the video data in the given
 * cursor table at the given {@code index}.
 */
private Matcher<VideoLibraryModel.Video> equalsVideoDataInCursor(final Object[][] cursorTable,
        final int index) {
    return new BaseMatcher<VideoLibraryModel.Video>() {
        @Override
        public boolean matches(final Object item) {
            final VideoLibraryModel.Video video = (VideoLibraryModel.Video) item;
            return video.getId().equals(cursorTable[VIDEO_ID_COLUMN_INDEX][index])
                    && video.getYear() == (Integer) cursorTable[VIDEO_YEAR_COLUMN_INDEX][index]
                    && video.getTopic().equals(cursorTable[VIDEO_TOPIC_COLUMN_INDEX][index])
                    && video.getTitle().equals(cursorTable[VIDEO_TITLE_COLUMN_INDEX][index])
                    && video.getDesc().equals(cursorTable[VIDEO_DESC_COLUMN_INDEX][index])
                    && video.getVid().equals(cursorTable[VIDEO_VID_COLUMN_INDEX][index])
                    && video.getSpeakers().equals(
                        cursorTable[VIDEO_SPEAKER_COLUMN_INDEX][index])
                    && video.getThumbnailUrl().equals(
                        cursorTable[VIDEO_THUMBNAIL_URL_COLUMN_INDEX][index]);
        }
        @Override
        public void describeTo(final Description description) {
            description.appendText("The Video does not match the data in table ")
                    .appendValue(cursorTable).appendText(" at index ").appendValue(index);
        }
    };
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:29,代码来源:VideoLibraryModelTest.java


注:本文中的org.hamcrest.BaseMatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。