@Test public void testWithRandomString() throws Exception { assertThat(converter.fromString("aaaa")).isFalse(); assertThat(converter.fromString("welcome true")).isFalse(); assertThat(converter.fromString("true welcome")).isFalse(); } }
@Test public void testNumbers() throws Exception { assertThat(converter.fromString("1")).isTrue(); assertThat(converter.fromString("2")).isFalse(); assertThat(converter.fromString("0")).isFalse(); }
@Test public void testMissingFlag() { final CLI cli = CLI.create("test") .addOption(new Option().setShortName("f").setFlag(true)) .addOption(new Option().setShortName("x")); final CommandLine evaluated = cli.parse(Arrays.asList("-x", "foo")); assertThat(evaluated.isFlagEnabled("f")).isFalse(); assertThat((String) evaluated.getOptionValue("x")).isEqualToIgnoringCase("foo"); }
@Test public void isIp() { assertThat(TextValidator.isIp("192.168.0.300")).isFalse(); assertThat(TextValidator.isIp("192.168.300.1")).isFalse(); assertThat(TextValidator.isIp("192.168.300")).isFalse(); assertThat(TextValidator.isIp("192.168.A3.1")).isFalse(); assertThat(TextValidator.isIp("192.168.0.1")).isTrue(); }
@Test public void testWithNullAndEmptyString() throws Exception { assertThat(converter.fromString(null)).isFalse(); assertThat(converter.fromString("")).isFalse(); }
@Test public void isMobileSimple() { assertThat(TextValidator.isMobileSimple(null)).isFalse(); assertThat(TextValidator.isMobileSimple("")).isFalse(); assertThat(TextValidator.isMobileSimple("1234a")).isFalse(); assertThat(TextValidator.isMobileSimple("1234561")).isFalse(); assertThat(TextValidator.isMobileSimple("11170998762")).isTrue(); }
@Test public void testIsNotWindows() throws IllegalAccessException { set("mac os x"); assertThat(ExecUtils.isWindows()).isFalse(); set("linux"); assertThat(ExecUtils.isWindows()).isFalse(); } }
@Test public void testYesNo() throws Exception { assertThat(converter.fromString("yes")).isTrue(); assertThat(converter.fromString("YeS")).isTrue(); assertThat(converter.fromString("no")).isFalse(); assertThat(converter.fromString("nO")).isFalse(); }
@Test public void testFatJarWithHTTPVerticle() throws IOException, InterruptedException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[]{}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getBoolean("clustered")).isFalse(); }
@Test public void testTrueFalse() throws Exception { assertThat(converter.fromString("true")).isTrue(); assertThat(converter.fromString("TruE")).isTrue(); assertThat(converter.fromString("fALse")).isFalse(); assertThat(converter.fromString("false")).isFalse(); }
@Test public void isUrl() { assertThat(TextValidator.isUrl("abc.com")).isFalse(); assertThat(TextValidator.isUrl("http://abc.c om")).isFalse(); assertThat(TextValidator.isUrl("http2://abc.com")).isFalse(); assertThat(TextValidator.isUrl("http://abc.com")).isTrue(); }
@Test public void testOnOff() throws Exception { assertThat(converter.fromString("on")).isTrue(); assertThat(converter.fromString("ON")).isTrue(); assertThat(converter.fromString("off")).isFalse(); assertThat(converter.fromString("oFf")).isFalse(); }
@Test public void isEmail() { assertThat(TextValidator.isEmail("abc")).isFalse(); assertThat(TextValidator.isEmail("abc@a")).isFalse(); assertThat(TextValidator.isEmail("中文@a.com")).isFalse(); assertThat(TextValidator.isEmail("abc@abc.com")).isTrue(); }
@Test public void isMobileExact() { assertThat(TextValidator.isMobileExact("1234a")).isFalse(); assertThat(TextValidator.isMobileExact("11170998762")).isFalse(); assertThat(TextValidator.isMobileExact("13970998762")).isTrue(); }
private void verifyCookie(Cookie cookie, @Nullable String value, int expiry) { assertThat(cookie.getPath()).isEqualTo("/"); assertThat(cookie.isHttpOnly()).isTrue(); assertThat(cookie.getMaxAge()).isEqualTo(expiry); assertThat(cookie.getSecure()).isFalse(); assertThat(cookie.getValue()).isEqualTo(value); }
@Test public void isDate() { assertThat(TextValidator.isDate("2011-02-29")).isFalse(); assertThat(TextValidator.isDate("201a-02-30")).isFalse(); assertThat(TextValidator.isDate("2011-0211")).isFalse(); assertThat(TextValidator.isDate("2011-03-11")).isTrue(); assertThat(TextValidator.isDate("2012-02-29")).isTrue(); }
@Test public void init_create_cookie() { when(request.getParameter("return_to")).thenReturn("/settings"); underTest.init(request, response); verify(response).addCookie(cookieArgumentCaptor.capture()); Cookie cookie = cookieArgumentCaptor.getValue(); assertThat(cookie.getName()).isEqualTo(AUTHENTICATION_COOKIE_NAME); assertThat(cookie.getValue()).isNotEmpty(); assertThat(cookie.getPath()).isEqualTo("/"); assertThat(cookie.isHttpOnly()).isTrue(); assertThat(cookie.getMaxAge()).isEqualTo(300); assertThat(cookie.getSecure()).isFalse(); }
@Test public void isTel() { // 含字母 assertThat(TextValidator.isTel("8802973a")).isFalse(); // 太长 assertThat(TextValidator.isTel("8908222222")).isFalse(); // 太短 assertThat(TextValidator.isTel("89081")).isFalse(); assertThat(TextValidator.isTel("89019739")).isTrue(); assertThat(TextValidator.isTel("020-89019739")).isTrue(); }
private void verifyCookie(Cookie cookie) { assertThat(cookie.getName()).isEqualTo("OAUTHSTATE"); assertThat(cookie.getValue()).isNotEmpty(); assertThat(cookie.getPath()).isEqualTo("/"); assertThat(cookie.isHttpOnly()).isTrue(); assertThat(cookie.getMaxAge()).isEqualTo(-1); assertThat(cookie.getSecure()).isFalse(); } }
@Test public void isLeapYear() { // 2008-01-09,整除4年, true Date date = new Date(108, 0, 9); assertThat(DateUtil.isLeapYear(date)).isTrue(); // 2000-01-09,整除400年,true date = new Date(100, 0, 9); assertThat(DateUtil.isLeapYear(date)).isTrue(); // 1900-01-09,整除100年,false date = new Date(0, 0, 9); assertThat(DateUtil.isLeapYear(date)).isFalse(); }