소스 검색

added code to test console

Nhu Nguyen 8 년 전
커밋
283d1b1dbf
4개의 변경된 파일194개의 추가작업 그리고 0개의 파일을 삭제
  1. 107
    0
      .gitignore
  2. 20
    0
      pom.xml
  3. 25
    0
      src/main/java/com/zipcoder/console/Console.java
  4. 42
    0
      src/test/java/com/zipcoder/console/ConsoleTest.java

+ 107
- 0
.gitignore 파일 보기

@@ -0,0 +1,107 @@
1
+.metadata
2
+bin/
3
+tmp/
4
+*.tmp
5
+*.bak
6
+*.swp
7
+*~.nib
8
+local.properties
9
+.settings/
10
+.loadpath
11
+.recommenders
12
+
13
+# External tool builders
14
+.externalToolBuilders/
15
+
16
+# Locally stored "Eclipse launch configurations"
17
+*.launch
18
+
19
+# PyDev specific (Python IDE for Eclipse)
20
+*.pydevproject
21
+
22
+# CDT-specific (C/C++ Development Tooling)
23
+.cproject
24
+
25
+# Java annotation processor (APT)
26
+.factorypath
27
+
28
+# PDT-specific (PHP Development Tools)
29
+.buildpath
30
+
31
+# sbteclipse plugin
32
+.target
33
+
34
+# Tern plugin
35
+.tern-project
36
+
37
+# TeXlipse plugin
38
+.texlipse
39
+
40
+# STS (Spring Tool Suite)
41
+.springBeans
42
+
43
+# Code Recommenders
44
+.recommenders/
45
+
46
+# Scala IDE specific (Scala & Java development for Eclipse)
47
+.cache-main
48
+.scala_dependencies
49
+.worksheet
50
+
51
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
52
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
53
+
54
+# User-specific stuff:
55
+.idea/**
56
+.idea/**/tasks.xml
57
+.idea/dictionaries
58
+
59
+# Sensitive or high-churn files:
60
+.idea/**/dataSources/
61
+.idea/**/dataSources.ids
62
+.idea/**/dataSources.xml
63
+.idea/**/dataSources.local.xml
64
+.idea/**/sqlDataSources.xml
65
+.idea/**/dynamic.xml
66
+.idea/**/uiDesigner.xml
67
+
68
+# Gradle:
69
+.idea/**/gradle.xml
70
+.idea/**/libraries
71
+.idea/*
72
+*.iml
73
+
74
+# CMake
75
+cmake-build-debug/
76
+
77
+# Mongo Explorer plugin:
78
+.idea/**/mongoSettings.xml
79
+
80
+## File-based project format:
81
+*.iws
82
+
83
+## Plugin-specific files:
84
+
85
+# IntelliJ
86
+/out/
87
+
88
+# mpeltonen/sbt-idea plugin
89
+.idea_modules/
90
+
91
+# JIRA plugin
92
+atlassian-ide-plugin.xml
93
+
94
+# Cursive Clojure plugin
95
+.idea/replstate.xml
96
+
97
+# Crashlytics plugin (for Android Studio and IntelliJ)
98
+com_crashlytics_export_strings.xml
99
+crashlytics.properties
100
+crashlytics-build.properties
101
+fabric.properties
102
+target/*
103
+
104
+.project
105
+.classpath
106
+.settings
107
+

+ 20
- 0
pom.xml 파일 보기

@@ -0,0 +1,20 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>com.zipcoder</groupId>
8
+    <artifactId>consoletest</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>4.12</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+    </dependencies>
18
+
19
+
20
+</project>

+ 25
- 0
src/main/java/com/zipcoder/console/Console.java 파일 보기

@@ -0,0 +1,25 @@
1
+package com.zipcoder.console;
2
+
3
+import java.io.InputStream;
4
+import java.io.PrintStream;
5
+import java.util.Scanner;
6
+
7
+public class Console {
8
+    private Scanner scanner;
9
+    private PrintStream out;
10
+
11
+    public Console(PrintStream out, InputStream in) {
12
+        this.out = out;
13
+        if (in != null) {
14
+            scanner = new Scanner(in);
15
+        }
16
+    }
17
+
18
+    public void print(String expectedString) {
19
+        out.print(expectedString);
20
+    }
21
+
22
+    public String nextLine() {
23
+        return scanner.nextLine();
24
+    }
25
+}

+ 42
- 0
src/test/java/com/zipcoder/console/ConsoleTest.java 파일 보기

@@ -0,0 +1,42 @@
1
+package com.zipcoder.console;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+import java.io.ByteArrayInputStream;
8
+import java.io.ByteArrayOutputStream;
9
+import java.io.InputStream;
10
+import java.io.PrintStream;
11
+
12
+public class ConsoleTest {
13
+
14
+    @Test
15
+    public void testPrint(){
16
+        //Given
17
+        String expectedString = "Hello";
18
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
19
+        PrintStream printStream = new PrintStream(outputStream);
20
+        Console console = new Console(printStream, null);
21
+
22
+        //When
23
+        console.print(expectedString);
24
+
25
+        //Then
26
+        String actualString = outputStream.toString();
27
+        Assert.assertEquals(expectedString, actualString);
28
+    }
29
+
30
+    @Test
31
+    public void testNextLine() {
32
+        String expectedString = "stay";
33
+        InputStream inputStream = new ByteArrayInputStream(expectedString.getBytes());
34
+        Console console = new Console(null, inputStream);
35
+
36
+        //When
37
+        String actualString = console.nextLine();
38
+
39
+        //Then
40
+        Assert.assertEquals(expectedString, actualString);
41
+    }
42
+}