示例#1
0
  @Test
  public void testCheckWhetherCorrectNumber() throws Exception {

    int a = Main.checkWhetherCorrectNumber(5);
    assertEquals(5, a);
    int b = Main.checkWhetherCorrectNumber(140);
    assertEquals(0, b);
  }
示例#2
0
 @Test
 public void testCheckBrac() throws Exception {
   String str = ")(ma)m((a";
   String str1 = "(mama)";
   String str2 = "((mama)";
   assertEquals(true, Main.checkBrac(str1, '(', ')'));
   assertEquals(false, Main.checkBrac(str, '(', ')'));
   assertEquals(false, Main.checkBrac(str2, '(', ')'));
 }
示例#3
0
 @Test
 public void testCheckBrackets() throws Exception {
   String str = ")(ma)m((a";
   String str1 = "[{(mama)}]";
   String str2 = "}((mama)";
   assertEquals(false, Main.checkBrackets(str));
   // 12assertEquals(true, Main.checkBrackets(str1));
   assertEquals(false, Main.checkBrackets(str2));
 }
  /*
   * osa 6
   */
  @Points("77.6")
  @Test
  public void manyCards() {
    Main.main(new String[0]);
    String[] rivit = io.getSysOut().split("\n");
    assertTrue("Et tulosta mitään", rivit.length > 0);
    for (String rivi : rivit) {
      assertTrue(
          "Print card info and owner name of card at the same line."
              + "Remove possible extra code from main()",
          rivi.toLowerCase().contains("pek") || rivi.toLowerCase().contains("bri"));
      assertFalse(
          "Print only one card info per line. Now you print line " + rivi,
          rivi.toLowerCase().contains("pek") && rivi.toLowerCase().contains("bri"));
    }
    ArrayList<String> pekka = new ArrayList<String>();
    ArrayList<String> matti = new ArrayList<String>();
    for (String rivi : rivit) {
      if (rivi.toLowerCase().contains("bri")) {
        matti.add(rivi);
      } else if (rivi.toLowerCase().contains("pek")) {
        pekka.add(rivi);
      }
    }

    tarkastaMatinRivit(matti);
    tarkastaPekanRivit(pekka);
  }
  /** Tests dynamically adding a jar file to the classpath. */
  @Test
  public void addJarToClasspath() throws Exception {
    assertFalse(
        new ClassPathResource("db/migration/V1__Initial_structure.sql.sql", getClassLoader())
            .exists());
    assertFalse(
        ClassUtils.isPresent("org.flywaydb.sample.migration.V1_2__Another_user", getClassLoader()));

    String jar = new ClassPathResource("flyway-sample.jar", getClassLoader()).getLocationOnDisk();
    assertTrue(new File(jar).isFile());
    Main.addJarOrDirectoryToClasspath(jar);

    assertTrue(
        new ClassPathResource("db/migration/V1__Initial_structure.sql", getClassLoader()).exists());
    assertTrue(
        ClassUtils.isPresent("org.flywaydb.sample.migration.V1_2__Another_user", getClassLoader()));

    Resource[] resources =
        new ClassPathScanner(getClassLoader())
            .scanForResources(new Location("classpath:db/migration"), "V1__", ".sql");
    assertEquals("db/migration/V1__Initial_structure.sql", resources[0].getLocation());

    Class<?>[] classes =
        new ClassPathScanner(getClassLoader())
            .scanForClasses(
                new Location("classpath:org/flywaydb/sample/migration"), SpringJdbcMigration.class);
    assertEquals("org.flywaydb.sample.migration.V1_2__Another_user", classes[0].getName());
  }
示例#6
0
 @Test
 public void testInit() throws Exception {
   String inputStr = "D1 D3 E5";
   ByteArrayInputStream in = new ByteArrayInputStream(inputStr.getBytes(StandardCharsets.UTF_8));
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   Main.init(in, out);
   assertEquals("29", out.toString());
 }
示例#7
0
  @Test
  public void test() throws IOException, SAXException {
    byte[] expected = StreamUtils.readStream(getClass().getResourceAsStream("expected.xml"));
    String result = Main.runSmooksTransform();

    StringBuffer s1 = StreamUtils.trimLines(new ByteArrayInputStream(expected));
    StringBuffer s2 = StreamUtils.trimLines(new ByteArrayInputStream(result.getBytes()));

    assertEquals("Expected:\n" + s1 + "\nActual:\n" + s2, s1.toString(), s2.toString());
  }
  @Test
  public void loadConfigurationFileBackslash() throws Exception {
    Properties properties = new Properties();

    String filename =
        new ClassPathResource("dynamic/pkg/runtime.conf", getClassLoader()).getLocationOnDisk();
    String[] args = new String[] {"-configFile=" + filename, "-configFileEncoding=UTF-8"};

    Main.loadConfiguration(properties, args);

    assertEquals(1, properties.size());
    assertEquals("at\\runtime", properties.getProperty("loaded"));
  }
  @Test
  public void testHtml() throws IOException {
    Path src = Paths.get("base/spec/spec.txt");
    Path dest = Files.createTempFile("test", ".tmp");

    try {
      Main.main(new String[] {src.toAbsolutePath().toString(), dest.toAbsolutePath().toString()});

      Path result = Paths.get("base/result/spec.html");
      assertEquals(Files.readAllLines(result), Files.readAllLines(dest));
    } finally {
      Files.delete(dest);
    }
  }
  /** Tests dynamically adding a directory to the default package of classpath. */
  @Test
  public void addDirectoryToClasspathDefaultPackage() throws Exception {
    assertFalse(new ClassPathResource("runtime.conf", getClassLoader()).exists());

    String folder = new ClassPathResource("dynamic/pkg2", getClassLoader()).getLocationOnDisk();
    Main.addJarOrDirectoryToClasspath(folder);

    assertTrue(new ClassPathResource("funtime.properties", getClassLoader()).exists());

    Resource[] resources =
        new ClassPathScanner(getClassLoader())
            .scanForResources(new Location("classpath:"), "fun", ".properties");
    assertEquals("funtime.properties", resources[1].getLocation());
  }
  /** Tests dynamically adding a directory to the classpath. */
  @Test
  public void addDirectoryToClasspath() throws Exception {
    assertFalse(new ClassPathResource("pkg/runtime.conf", getClassLoader()).exists());

    String folder = new ClassPathResource("dynamic", getClassLoader()).getLocationOnDisk();
    Main.addJarOrDirectoryToClasspath(folder);

    assertTrue(new ClassPathResource("pkg/runtime.conf", getClassLoader()).exists());

    Resource[] resources =
        new ClassPathScanner(getClassLoader())
            .scanForResources(new Location("classpath:pkg"), "run", ".conf");
    assertEquals("pkg/runtime.conf", resources[0].getLocation());
  }
  @Test
  public void loadConfigurationFile() throws Exception {
    Properties properties = new Properties();
    properties.put("existing", "still there!");
    properties.put("override", "loses :-(");

    String filename =
        new ClassPathResource("test.properties", getClassLoader()).getLocationOnDisk();
    String[] args = new String[] {"-configFile=" + filename, "-configFileEncoding=UTF-8"};

    Main.loadConfiguration(properties, args);

    assertEquals(4, properties.size());
    assertEquals("still there!", properties.getProperty("existing"));
    assertEquals("räbbit 123", properties.getProperty("roger"));
    assertEquals("wins :-)", properties.getProperty("override"));
  }
 @Before
 public void setUp() {
   oldClassLoader = getClassLoader();
   Main.initLogging(Level.INFO);
 }
示例#14
0
 @Test
 public void testTriple() {
   assertThat(Main.triple("AB"), equalTo("ABABAB"));
 }