• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Koan类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: switchStatementSwitchValues

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void switchStatementSwitchValues() {
    // Try different (primitive) types for 'c'
    // Which types do compile?
    // Does boxing work?
    char c = 'a';
    String result = "Basic ";
    switch (c) {
        case 'a':
            result += "One";
            break;
        default:
            result += "Nothing";
    }
    assertEquals(result, "Basic One");
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:17,代码来源:AboutConditionals.java


示例2: forLoopContinueLabel

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void forLoopContinueLabel() {
    int count = 0;
    outerLabel:
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 6; j++) {
            count++;
            if (count > 2) {
                continue outerLabel;
            }
        }
        count += 10;
    }
    // What does continue with a label mean?
    // What gets executed? Where does the program flow continue?
    assertEquals(count, 8);
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:18,代码来源:AboutLoops.java


示例3: customObjectSerializationWithTransientFields

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void customObjectSerializationWithTransientFields() throws FileNotFoundException, IOException, ClassNotFoundException {
    // Note that this kind of access of fields is not good OO practice.
    // But let's focus on serialization here :)
    Car car = new Car();
    car.engine = new Engine("diesel");
    File file = new File("SerializeFile");
    file.deleteOnExit();
    ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(file));
    os.writeObject(car);
    os.close();

    ObjectInputStream is = null;
    try {
        is = new ObjectInputStream(new FileInputStream("SerializeFile"));
        Car deserializedCar = (Car) is.readObject();
        assertEquals(deserializedCar.engine.type, __);
    } finally {
        closeStream(is);
    }
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:22,代码来源:AboutSerialization.java


示例4: customSerializationWithUnserializableFields

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void customSerializationWithUnserializableFields() throws FileNotFoundException, IOException {
    Boat boat = new Boat();
    boat.engine = new Engine("diesel");
    File file = new File("SerializeFile");
    file.deleteOnExit();
    ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(file));
    String marker = "Start ";
    try {
        os.writeObject(boat);
    } catch (NotSerializableException e) {
        marker += "Exception";
    }
    os.close();
    assertEquals(marker, __);
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:17,代码来源:AboutSerialization.java


示例5: serializeWithInheritanceWhenParentNotSerializable

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void serializeWithInheritanceWhenParentNotSerializable() throws FileNotFoundException, IOException, ClassNotFoundException {
    MilitaryPlane p = new MilitaryPlane("F22");

    ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("SerializeFile"));
    os.writeObject(p);
    os.close();

    ObjectInputStream is = null;
    try {
        is = new ObjectInputStream(new FileInputStream("SerializeFile"));
        MilitaryPlane otherPlane = (MilitaryPlane) is.readObject();
        // Does this surprise you?
        assertEquals(otherPlane.name, __);

        // Think about how serialization creates objects...
        // It does not use constructors! But if a parent object is not serializable
        // it actually uses constructors and if the fields are not in a serializable class...
        // unexpected things - like this - may happen
    } finally {
        closeStream(is);
    }
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:24,代码来源:AboutSerialization.java


示例6: betterFileWritingAndReading

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void betterFileWritingAndReading() throws IOException {
    File file = new File("file.txt");
    file.deleteOnExit();
    FileWriter fw = new FileWriter(file);
    PrintWriter pw = new PrintWriter(fw);
    pw.println("First line");
    pw.println("Second line");
    pw.close();

    FileReader fr = new FileReader(file);
    BufferedReader br = null;
    try {
        br = new BufferedReader(fr);
        assertEquals(br.readLine(), __); // first line
        assertEquals(br.readLine(), __); // second line
        assertEquals(br.readLine(), __); // what now?
    } finally {
        // anytime you open access to a file, you should close it or you may
        // lock it from other processes (ie frustrate people)
        closeStream(br);
    }
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:24,代码来源:AboutFileIO.java


示例7: lookMaNoCloseWithMultipleResources

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void lookMaNoCloseWithMultipleResources() throws IOException {
    String str = "first line"
            + System.lineSeparator()
            + "second line";
    InputStream is = new ByteArrayInputStream(str.getBytes());
    String line;
    //multiple resources in the same try declaration
    try (BufferedReader br =
                 new BufferedReader(
                         new FileReader("I do not exist!"));
         BufferedReader brFromString =
                 new BufferedReader(
                         new InputStreamReader(is))
    ) {
        line = br.readLine();
        line += brFromString.readLine();
    } catch (IOException e) {
        line = "error";
    }
    assertEquals(line, __);
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:23,代码来源:AboutTryWithResources.java


示例8: lookMaNoClose

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void lookMaNoClose() {
    String str = "first line"
            + System.lineSeparator()
            + "second line";
    InputStream is = new ByteArrayInputStream(str.getBytes());
    String line;
    /* BufferedReader implementing @see java.lang.AutoCloseable interface */
    try (BufferedReader br =
                 new BufferedReader(
                         new InputStreamReader(is))) {
        line = br.readLine();
        //br guaranteed to be closed
    } catch (IOException e) {
        line = "error";
    }
    assertEquals(line, __);
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:19,代码来源:AboutTryWithResources.java


示例9: simpleAnonymousMock

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void simpleAnonymousMock() {
    // HINT: pass a safe Collaborator implementation to constructor
    // new ClassUnderTest(new Collaborator(){... it should not be the
    // objective of this test to test that collaborator, so replace it
    new ClassUnderTest().doSomething();
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:8,代码来源:AboutMocks.java


示例10: switchStatementFallThrough

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void switchStatementFallThrough() {
    int i = 1;
    String result = "Basic ";
    switch (i) {
        case 1:
            result += "One";
        case 2:
            result += "Two";
        default:
            result += "Nothing";
    }
    assertEquals(result, "Basic OneTwoNothing");
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:15,代码来源:AboutConditionals.java


示例11: stringIsEmpty

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void stringIsEmpty() {
    assertEquals("".isEmpty(), true);
    assertEquals("one".isEmpty(), false);
    assertEquals(new String().isEmpty(), true);
    assertEquals(new String("").isEmpty(), true);
    assertEquals(new String("one").isEmpty(), false);
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:9,代码来源:AboutStrings.java


示例12: returnInFinallyBlock

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void returnInFinallyBlock() {
    StringBuilder whatHappened = new StringBuilder();
    // Which value will be returned here?
    assertEquals(returnStatementsEverywhere(whatHappened), "from finally");
    assertEquals(whatHappened.toString(), "try, catch, finally");
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:8,代码来源:AboutExceptions.java


示例13: stringTrim

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void stringTrim() {
    assertEquals("".trim(), "");
    assertEquals("one".trim(), "one");
    assertEquals(" one more time".trim(), "one more time");
    assertEquals(" one more time         ".trim(), "one more time");
    assertEquals(" and again\t".trim(), "and again");
    assertEquals("\t\t\twhat about now?\t".trim(), "what about now?");
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:10,代码来源:AboutStrings.java


示例14: base64Decoding

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void base64Decoding() {
    // Decode the Base64 encodedText
    // This uses the basic Base64 decoding scheme but there are corresponding
    // getMimeDecoder and getUrlDecoder methods available if you require a
    // different format/Base64 Alphabet
    byte[] decodedBytes = Base64.getDecoder().decode(__);
    try {
        String decodedText = new String(decodedBytes, "utf-8");
        assertEquals(plainText, decodedText);
    } catch (UnsupportedEncodingException ex) {}
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:13,代码来源:AboutBase64.java


示例15: mapReduce

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void mapReduce() {
    OptionalDouble averageLengthOptional = places.stream()
            .mapToInt(String::length)
            .average();
    double averageLength = Math.round(averageLengthOptional.getAsDouble());
    assertEquals(averageLength, __);
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:9,代码来源:AboutStreams.java


示例16: parallelMapReduce

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void parallelMapReduce() {
    int lengthSum = places.parallelStream()
            .mapToInt(String::length)
            .sum();
    assertEquals(lengthSum, __);
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:8,代码来源:AboutStreams.java


示例17: switchStatementCrazyFallThrough

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void switchStatementCrazyFallThrough() {
    int i = 5;
    String result = "Basic ";
    switch (i) {
        case 1:
            result += "One";
        default:
            result += "Nothing";
        case 2:
            result += "Two";
    }
    assertEquals(result, "Basic NothingTwo");
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:15,代码来源:AboutConditionals.java


示例18: rangeToList

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void rangeToList() {
    List<Integer> range = IntStream.range(1, 4)
            .boxed()
            .collect(Collectors.toList());
    assertEquals(range, __);
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:8,代码来源:AboutStreams.java


示例19: equalsMethodCanBeChangedBySubclassesToTestsIfTwoObjectsAreEqualExample

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void equalsMethodCanBeChangedBySubclassesToTestsIfTwoObjectsAreEqualExample() {
    Integer value1 = new Integer(4);
    Integer value2 = new Integer(2 + 2);
    assertEquals(value1.equals(value2), true);
    assertEquals(value1, value1);
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:8,代码来源:AboutEquality.java


示例20: upcastAndPolymorphism

import com.sandwich.koan.Koan; //导入依赖的package包/类
@Koan
public void upcastAndPolymorphism() {
    Child child = new Child();
    Parent parentReference = child;
    // If the result is unexpected, consider the difference between an instance and its reference
    assertEquals(parentReference.complain(), "Are we there yet!!");
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:8,代码来源:AboutCasting.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PreKeyStore类代码示例发布时间:2022-05-23
下一篇:
Java Profile类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap