### Question:
CubePathBuilder { public String build() { Assert.notNull(schema); Assert.isFalse(tempDir != null && backup, "tempDir is not allowed when backup is present, vice versa"); StringBuilder path = new StringBuilder(); if (absolute) { path.append(PATH_SVC.getSwiftPath()).append('/'); } path.append(backup ? schema.getBackupDir() : schema.getDir()); if (tempDir != null) { path.append('/').append(tempDir); } if (tableKey != null) { path.append('/').append(tableKey.getId()); } if (segOrder != null) { path.append("/seg").append(segOrder); } if (columnId != null) { path.append('/').append(columnId); } return path.toString(); } CubePathBuilder();  CubePathBuilder(SegmentKey segKey); CubePathBuilder asAbsolute(); CubePathBuilder setSwiftSchema(SwiftDatabase schema); CubePathBuilder setTempDir(int tempDir); CubePathBuilder asBackup(); CubePathBuilder setTableKey(SourceKey tableKey); CubePathBuilder setSegOrder(int segOrder); CubePathBuilder setColumnId(String columnId); String build(); @Override String toString();  }### Answer:
@Test(expected = RuntimeException.class) public void testWrongBuild() { new CubePathBuilder().build(); }
@Test public void testBuild() { SourceKey tableKey = new SourceKey("table1"); SwiftDatabase swiftSchema = SwiftDatabase.CUBE; String columnId = "column1"; int segOrder = 10; String path = new CubePathBuilder().setSwiftSchema(swiftSchema) .setTempDir(0) .setTableKey(tableKey) .setSegOrder(segOrder) .setColumnId(columnId).build(); Assert.assertEquals(String.format("%s/0/%s/seg%d/%s", swiftSchema.getDir(), tableKey, segOrder, columnId), path); path = new CubePathBuilder().setSwiftSchema(swiftSchema) .setTableKey(tableKey) .setSegOrder(segOrder) .setColumnId(columnId).build(); Assert.assertEquals(String.format("%s/%s/seg%d/%s", swiftSchema.getDir(), tableKey, segOrder, columnId), path); path = new CubePathBuilder().setSwiftSchema(swiftSchema) .setTableKey(tableKey) .setSegOrder(segOrder).build(); Assert.assertEquals(String.format("%s/%s/seg%d", swiftSchema.getDir(), tableKey, segOrder), path); path = new CubePathBuilder().setSwiftSchema(swiftSchema) .setTableKey(tableKey).build(); Assert.assertEquals(String.format("%s/%s", swiftSchema.getDir(), tableKey), path); path = new CubePathBuilder().setSwiftSchema(swiftSchema).build(); Assert.assertEquals(String.format("%s", swiftSchema.getDir()), path); path = new CubePathBuilder().setSwiftSchema(swiftSchema) .setTableKey(tableKey) .setSegOrder(segOrder).asBackup().build(); Assert.assertEquals(String.format("%s/%s/seg%d", swiftSchema.getBackupDir(), tableKey, segOrder), path); path = new CubePathBuilder().setSwiftSchema(swiftSchema) .setTableKey(tableKey) .setSegOrder(segOrder).asAbsolute().build(); Assert.assertEquals(String.format("%s/%s/%s/seg%d", basePath, swiftSchema.getDir(), tableKey, segOrder), path); }
@Test public void testBuildFromSegKey() { SourceKey tableKey = new SourceKey("table1"); SwiftDatabase swiftSchema = SwiftDatabase.CUBE; int segOrder = 10; SegmentKey segKey = EasyMock.mock(SegmentKey.class); EasyMock.expect(segKey.getSwiftSchema()).andReturn(swiftSchema).anyTimes(); EasyMock.expect(segKey.getTable()).andReturn(tableKey).anyTimes(); EasyMock.expect(segKey.getOrder()).andReturn(segOrder).anyTimes(); EasyMock.replay(segKey); String path = new CubePathBuilder(segKey).build(); Assert.assertEquals(String.format("%s/%s/seg%d", swiftSchema.getDir(), tableKey, segOrder), path); }