Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.apache.http.Header;
import org.apache.http.HttpMessage;

public class Main {
    public static void assertNotHasHeader(HttpMessage message, String unexpectedHeader) {
        if (containsHeader(message, unexpectedHeader)) {
            throw new AssertionError("Unexpected header '" + unexpectedHeader + "' in '" + toString(message) + "'");
        }
    }

    public static boolean containsHeader(HttpMessage message, String expectedHeader) {
        for (Header header : message.getAllHeaders()) {
            if (expectedHeader.equals(header.toString())) {
                return true;
            }
        }
        return false;
    }

    public static String toString(HttpMessage message) {
        StringBuilder sb = new StringBuilder();
        for (Header header : message.getAllHeaders()) {
            sb.append(header.toString());
            sb.append("\n");
        }
        return sb.toString();
    }
}