當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。